-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from rollbar/jon/delayed-job-sequel-as-json-e…
…rror Delayed job fix on job serialization
- Loading branch information
Showing
3 changed files
with
56 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
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 = job.as_json | ||
handler_parent = job_data['job'] ? job_data['job'] : job_data | ||
handler_parent['handler'] = handler_data | ||
def to_hash | ||
job_data = extract_job_data | ||
|
||
job_data | ||
end | ||
handler_parent = job_data['job'] ? job_data['job'] : job_data | ||
handler_parent['handler'] = handler_data | ||
|
||
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 | ||
|
||
def handler_data | ||
payload_object = job.payload_object | ||
|
||
private | ||
return payload_object unless payload_object.respond_to?(:object) | ||
|
||
def handler_data | ||
object = job.payload_object.object | ||
object_data(payload_object.object) | ||
end | ||
|
||
{ | ||
:method_name => job.payload_object.method_name, | ||
:args => job.payload_object.args, | ||
:object => object.is_a?(Class) ? object.name : object.to_s | ||
} | ||
rescue | ||
{} | ||
def object_data(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
spec/rollbar/plugins/delayed_job/job_data.rb → ...lbar/plugins/delayed_job/job_data_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters