Skip to content

Commit

Permalink
Fixes: #472
Browse files Browse the repository at this point in the history
If there is every an error within the payload object itself, within delayed jobs, rollbar does not propagate that error, since delayed job fails to call the :invoke_job lifecycle hook and instead calls the :failure lifecycle hook.
  • Loading branch information
richvorp committed May 30, 2017
1 parent 9ef189d commit da3708b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rollbar/plugins/delayed_job/job_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def handler_data
return payload_object unless payload_object.respond_to?(:object)

object_data(payload_object.object)
rescue
payload_object = job
end

def object_data(object)
Expand Down
3 changes: 3 additions & 0 deletions lib/rollbar/plugins/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class << self
class RollbarPlugin < ::Delayed::Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job, &Delayed::invoke_job_callback)
lifecycle.after(:failure) do |worker, job, *args, &block|
Delayed.report(job.last_error, job)
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/rollbar/plugins/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def do_job_please!(a, b)
end
end

context 'with failed deserialization' do
it 'sends the exception' do
expect(Rollbar).to receive(:scope).with(kind_of(Hash)).and_call_original
allow_any_instance_of(Delayed::Backend::Base).to receive(:payload_object).and_raise(Delayed::DeserializationError)
expect_any_instance_of(Rollbar::Notifier).to receive(:error)

FailingJob.new.delay.do_job_please!(:foo, :bar)
end
end

describe '.build_job_data' do
let(:job) { double(:payload_object => {}) }
Expand Down

0 comments on commit da3708b

Please sign in to comment.