Skip to content

Commit

Permalink
Don't rely on #as_json for delayed_job payload_object
Browse files Browse the repository at this point in the history
This will avoid infinite loops with ActiveRecord class jobs.

Fix #369
  • Loading branch information
Jon de Andres committed May 6, 2016
1 parent d532bfc commit 0891bad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
21 changes: 18 additions & 3 deletions lib/rollbar/plugins/delayed_job/job_data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'yaml'

class JobData
attr_reader :job

Expand All @@ -7,10 +9,23 @@ def initialize(job)

def to_hash
job_data = job.as_json
# Here job_data['handler'] is a YAML object comming
# from the storage backend
job_data['handler'] = job.payload_object.as_json
handler_parent = job_data['job'] ? job_data['job'] : job_data
handler_parent['handler'] = handler_data

job_data
end

private

def handler_data
object = job.payload_object.object

{
:method_name => job.payload_object.method_name,
:args => job.payload_object.args,
:object => object.is_a?(Class) ? object.name : object.to_s
}
rescue
{}
end
end
15 changes: 14 additions & 1 deletion spec/rollbar/plugins/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,20 @@ def do_job_please!(a, b)
end

context 'with attempts > configuration.dj_threshold' do
let(:job) { double(:attempts => 6) }
let(:object) do
double(:to_s => 'foo')
end
let(:payload_object) do
double(:method_name => 'foo',
:args => [1, 2],
:object => object)
end
let(:job) do
double(
:attempts => 6,
:job => { :payload_object => payload_object }
)
end

it 'returns true' do
expect(described_class.skip_report?(job)).to be(false)
Expand Down

0 comments on commit 0891bad

Please sign in to comment.