Skip to content

Client#page return valid results if old job/worker class no longer exists #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/gush/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def rm(workflow_id)
option :start, type: :numeric, default: nil
option :stop, type: :numeric, default: nil
def list(start=nil, stop=nil)
workflows = client.workflow_ids(start, stop).map do |id|
client.find_workflow(id)
end
workflows = client.workflows(start, stop)

rows = workflows.map do |workflow|
[workflow.id, (Time.at(workflow.started_at) if workflow.started_at), workflow.class, {alignment: :center, value: status_for(workflow)}]
Expand Down
8 changes: 7 additions & 1 deletion lib/gush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ def workflow_ids(start=nil, stop=nil, by_ts: false, order: :asc)
end

def workflows(start=nil, stop=nil, **kwargs)
workflow_ids(start, stop, **kwargs).map { |id| find_workflow(id) }
workflow_ids(start, stop, **kwargs).map do |id|
find_workflow(id)
rescue WorkflowClassDoesNotExist, JobClassDoesNotExist
nil
end.compact
end

def workflows_count
Expand Down Expand Up @@ -285,6 +289,8 @@ def workflow_from_hash(hash, nodes = [])
globals: hash[:globals],
internal_state: internal_state
)
rescue NameError
raise WorkflowClassDoesNotExist.new("Workflow #{hash[:klass]} doesn't exist")
end

def redis
Expand Down
2 changes: 2 additions & 0 deletions lib/gush/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module Gush
class WorkflowNotFound < StandardError; end
class WorkflowClassDoesNotExist < StandardError; end
class JobClassDoesNotExist < StandardError; end
class DependencyLevelTooDeep < StandardError; end
end
2 changes: 2 additions & 0 deletions lib/gush/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def to_json(options = {})

def self.from_hash(hash)
hash[:klass].constantize.new(hash)
rescue NameError
raise JobClassDoesNotExist.new("Job #{hash[:klass]} doesn't exist")
end

def output(data)
Expand Down
6 changes: 6 additions & 0 deletions spec/gush/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,11 @@
expect(job.started_at).to eq(55)
expect(job.enqueued_at).to eq(444)
end

it "raises JobClassDoesNotExist if the job class is no longer defined" do
expect {
described_class.from_hash({klass: 'NonExistentJob'})
}.to raise_error(Gush::JobClassDoesNotExist)
end
end
end
34 changes: 34 additions & 0 deletions spec/gush/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,40 @@ def configure(*args)
flow = TestWorkflow.create
expect(Gush::Workflow.page.map(&:id)).to eq([flow.id])
end

it "does not error if a stored workflow class is no longer defined in the codebase" do
flow = TestWorkflow.create
called = false
allow_any_instance_of(TestWorkflow).to receive(:to_hash).and_wrap_original do |original, *args|
called = true
original.call(*args).merge({name: 'OldDeletedWorkflow', klass: 'OldDeletedWorkflow'})
end
expect {
flow.save
Gush::Workflow.page
}.not_to raise_error
expect {
Gush::Client.new.find_workflow(flow.id)
}.to raise_error(Gush::WorkflowClassDoesNotExist)
expect(called).to be(true)
end

it "does not error if a workflow's job class is no longer defined" do
flow = TestWorkflow.create
called = false
allow_any_instance_of(Gush::Job).to receive(:as_json).and_wrap_original do |original, *args|
called = true
original.call(*args).merge({ klass: 'OldDeletedJob'})
end
flow.save
expect {
Gush::Workflow.page
}.not_to raise_error
expect {
Gush::Client.new.find_workflow(flow.id)
}.to raise_error(Gush::JobClassDoesNotExist)
expect(called).to be(true)
end
end

describe "#save" do
Expand Down