-
Notifications
You must be signed in to change notification settings - Fork 279
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
Dont call as_json on Delayed::Backend::Sequel::Job #473
Dont call as_json on Delayed::Backend::Sequel::Job #473
Conversation
We are seeing an error in Rollbar, when using Sequel and Delayed Job. In this file: https://github.com/rollbar/rollbar-gem/blob/master/lib/rollbar/plugins/delayed_job/job_data.rb#L9 we are calling on @as_json on this class in Delayed Job Sequel I updated Rollbar to just use #to_hash, if #as_json is not defined. |
instead call #to_hash, and turn all the keys to strings, to keep the rest of the implementation untouched
df4d175
to
81bf65c
Compare
Hey @davidbegin, thanks for this. Let me test it and we'll merge it. |
@@ -6,7 +6,12 @@ def initialize(job) | |||
end | |||
|
|||
def to_hash | |||
job_data = job.as_json | |||
job_data = if job.respond_to?(:as_json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should extract this code into its own method. And also, we should ensure that job
responds to #to_hash
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing this, I will work on those changes right now.
As I started to add specs to cover if the job object didn't respond to #as_json or #to_hash I noticed various problems. Here are my debugging notes: First I noticed that the spec file for JobData is not being run, because it doesn't end with _spec. spec/rollbar/plugins/delayed_job/job_data.rb Once I update to job_data_spec, and run the specs, I get: cannot load such file -- rollbar/delayed_job (LoadError) I am not sure what is trying to be loaded, as there is no rollbar/delayed_job file. this triggers: spec/rollbar/plugins/delayed_job/job_data_spec.rb:12:in `<top (required)>': uninitialized constant Rollbar::Delayed (NameError)'` then I noticed that the spec is testing the class describe Rollbar::Delayed::JobData do but if we open up: lib/rollbar/plugins/delayed_job/job_data.rb We see it's only declared as class JobData and not in the When I search to see where lib/rollbar/plugins/delayed_job/plugin.rb And it is indeed called within the So next I place When I run the specs I still get the error: spec/rollbar/plugins/delayed_job/job_data_spec.rb:12:in `<top (required)>': uninitialized constant Rollbar::Delayed (NameError)'` So I require the require 'rollbar/plugins/delayed_job/job_data' And the spec finally runs! expected `{"attempts"=>1, "priority"=>0, "handler"=>{}}.eql?({"priority"=>0, "attempts"=>1, "handler"=>{"foo"=>"bar"}})` to return true, got false I had a feeling that it was raising an error, and being caught in the handler_object method, uninitialized constant Delayed::Backend::Base::DeserializationError I assumed this was because I commented out the So I instead added Now the spec knows about undefined method `object' for {"foo"=>"bar"}:Hash` Which is from the first line in the handler_object method: object = job.payload_object.object
So far this is where I have got, but since I going down a rabbit-hole, I thought it might be good to share my findings and get some help. Thanks! |
Hey @davidbegin, thank you very much for the notes. You've found a missing piece we forgot to move when we added the plugins architecture. So, We'll do this change ourself and check that the specs are passing in master. After that, I think it's a good starting for your PR. |
@jondeandres Has there been any movement on this PR? Is there anything I could do to help? Thanks! |
instead call #to_hash, and turn all the keys to strings, to
keep the rest of the implementation untouched