diff --git a/lib/rollbar/plugins/delayed_job/job_data.rb b/lib/rollbar/plugins/delayed_job/job_data.rb index 1209cc14..dc1dc201 100644 --- a/lib/rollbar/plugins/delayed_job/job_data.rb +++ b/lib/rollbar/plugins/delayed_job/job_data.rb @@ -1,34 +1,45 @@ -class JobData - attr_reader :job +module Rollbar + module Delayed + class JobData + attr_reader :job - def initialize(job) - @job = job - end + def initialize(job) + @job = job + end - def to_hash - job_data = if job.respond_to?(:as_json) - job.as_json - else - Hash[job.to_hash.map { |k, v| [k.to_s, v] }] - end + def to_hash + job_data = extract_job_data - handler_parent = job_data['job'] ? job_data['job'] : job_data - handler_parent['handler'] = handler_data + handler_parent = job_data['job'] ? job_data['job'] : job_data + handler_parent['handler'] = handler_data - job_data - end + job_data + end + + private + + def extract_job_data + if job.respond_to?(:as_json) + job.as_json + else + Hash[job.to_hash.map { |k, v| [k.to_s, v] }] + end + end - private + def handler_data + payload_object = job.payload_object - def handler_data - object = job.payload_object.object + return payload_object unless payload_object.respond_to?(:object) - { - :method_name => job.payload_object.method_name, - :args => job.payload_object.args, - :object => object.is_a?(Class) ? object.name : object.to_s - } - rescue - {} + 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 end end diff --git a/spec/delayed/backend/test.rb b/spec/delayed/backend/test.rb index d024ddb5..af359722 100644 --- a/spec/delayed/backend/test.rb +++ b/spec/delayed/backend/test.rb @@ -1,4 +1,5 @@ require 'ostruct' +require 'delayed_job' require 'delayed/backend/base' # This code is taken from delayed_job/spec/delayed/backend/test.rb. diff --git a/spec/rollbar/plugins/delayed_job/job_data.rb b/spec/rollbar/plugins/delayed_job/job_data_spec.rb similarity index 93% rename from spec/rollbar/plugins/delayed_job/job_data.rb rename to spec/rollbar/plugins/delayed_job/job_data_spec.rb index 58b31d1c..2df0e000 100644 --- a/spec/rollbar/plugins/delayed_job/job_data.rb +++ b/spec/rollbar/plugins/delayed_job/job_data_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -require 'rollbar/delayed_job' +require 'rollbar/plugins/delayed_job/job_data' require 'delayed/backend/test' describe Rollbar::Delayed::JobData do