Skip to content
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

Fix CLI to display removed/renamed jobs #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/gush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require "gush/configuration"
require "gush/errors"
require "gush/job"
require "gush/nil_job"
require "gush/worker"
require "gush/workflow"

Expand Down
2 changes: 2 additions & 0 deletions lib/gush/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def to_json(options = {})

def self.from_hash(hash)
hash[:klass].constantize.new(hash)
rescue NameError
Gush::NilJob.new(hash)
end

def output(data)
Expand Down
7 changes: 7 additions & 0 deletions lib/gush/nil_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Gush
class NilJob < Job
def name
@name ||= "Removed - #{klass}|#{id}"
end
end
end
85 changes: 59 additions & 26 deletions spec/gush/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,66 @@
end

describe ".from_hash" do
it "properly restores state of the job from hash" do
job = described_class.from_hash(
{
klass: 'Gush::Job',
id: '702bced5-bb72-4bba-8f6f-15a3afa358bd',
incoming: ['a', 'b'],
outgoing: ['c'],
failed_at: 123,
finished_at: 122,
started_at: 55,
enqueued_at: 444
}
)
context 'when the job is existed' do
it "properly restores state of the job from hash" do
job = described_class.from_hash(
{
klass: 'Gush::Job',
id: '702bced5-bb72-4bba-8f6f-15a3afa358bd',
incoming: ['a', 'b'],
outgoing: ['c'],
failed_at: 123,
finished_at: 122,
started_at: 55,
enqueued_at: 444
}
)

expect(job.id).to eq('702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.name).to eq('Gush::Job|702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.class).to eq(Gush::Job)
expect(job.klass).to eq("Gush::Job")
expect(job.finished?).to eq(true)
expect(job.failed?).to eq(true)
expect(job.enqueued?).to eq(true)
expect(job.incoming).to eq(['a', 'b'])
expect(job.outgoing).to eq(['c'])
expect(job.failed_at).to eq(123)
expect(job.finished_at).to eq(122)
expect(job.started_at).to eq(55)
expect(job.enqueued_at).to eq(444)
expect(job.id).to eq('702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.name).to eq('Gush::Job|702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.class).to eq(Gush::Job)
expect(job.klass).to eq("Gush::Job")
expect(job.finished?).to eq(true)
expect(job.failed?).to eq(true)
expect(job.enqueued?).to eq(true)
expect(job.incoming).to eq(['a', 'b'])
expect(job.outgoing).to eq(['c'])
expect(job.failed_at).to eq(123)
expect(job.finished_at).to eq(122)
expect(job.started_at).to eq(55)
expect(job.enqueued_at).to eq(444)
end
end

context 'when the job is removed' do
it "properly restores state of the job from hash" do
job = described_class.from_hash(
{
klass: 'Gush::RemovedJob',
id: '702bced5-bb72-4bba-8f6f-15a3afa358bd',
incoming: ['a', 'b'],
outgoing: ['c'],
failed_at: 123,
finished_at: 122,
started_at: 55,
enqueued_at: 444
}
)

expect(job.id).to eq('702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.name).to eq('Removed - Gush::RemovedJob|702bced5-bb72-4bba-8f6f-15a3afa358bd')
expect(job.class).to eq(Gush::NilJob)
expect(job.klass).to eq("Gush::RemovedJob")
expect(job.finished?).to eq(true)
expect(job.failed?).to eq(true)
expect(job.enqueued?).to eq(true)
expect(job.incoming).to eq(['a', 'b'])
expect(job.outgoing).to eq(['c'])
expect(job.failed_at).to eq(123)
expect(job.finished_at).to eq(122)
expect(job.started_at).to eq(55)
expect(job.enqueued_at).to eq(444)
end
end
end
end
14 changes: 14 additions & 0 deletions spec/gush/nil_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

describe Gush::NilJob do
describe '#name' do
it 'prepends "Removed - "' do
job = described_class.from_hash(
klass: 'Gush::RemovedJob',
id: '702bced5-bb72-4bba-8f6f-15a3afa358bd'
)

expect(job.name).to eq('Removed - Gush::RemovedJob|702bced5-bb72-4bba-8f6f-15a3afa358bd')
end
end
end