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

Delayed job fix on job serialization #512

Merged
merged 3 commits into from
Sep 1, 2016
Merged
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
61 changes: 40 additions & 21 deletions lib/rollbar/plugins/delayed_job/job_data.rb
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
1 change: 1 addition & 0 deletions spec/delayed/backend/test.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
require 'spec_helper'

require 'rollbar/delayed_job'
require 'rollbar/plugins/delayed_job/job_data'
require 'delayed/backend/test'

# In delayed_job/lib/delayed/syck_ext.rb YAML.load_dj
# is broken cause it's defined as an instance method
# instead of module/class method. This is breaking
# the tests for ruby 1.8.7
if YAML.parser.class.name =~ /syck|yecht/i
module YAML
def self.load_dj(yaml)
# See https://github.com/dtao/safe_yaml
# When the method is there, we need to load our YAML like this...
respond_to?(:unsafe_load) ? load(yaml, :safe => false) : load(yaml)
end
end
end

describe Rollbar::Delayed::JobData do
describe '#to_hash' do
let(:handler) { { 'foo' => 'bar' } }
Expand Down