-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix accessing provider_job_id inside active jobs for sidekiq adapter #25961
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Looks fine to me. Not sure if you need the same support for the other adapters + tests. |
Build failures are unrelated. |
We need tests for sure. |
@@ -37,7 +37,7 @@ class JobWrapper #:nodoc: | |||
include Sidekiq::Worker | |||
|
|||
def perform(job_data) | |||
Base.execute job_data | |||
Base.execute job_data.merge('provider_job_id' => jid) |
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.
If this is being done here is it still needed to set the provider_job_id
in the enqueue
method?
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.
Yeah we still need to set it in the enqueue
method so we can access it outside the job (not inside). ie:
job = SomeJob.perform_later
jid = job.provider_job_id
@rafaelfranca ok, so could you give me any idea how can I test this? I believe that all we need to do here is to make sure that |
Something like this test but exposing the value that was inside the job? https://github.com/rails/rails/blob/master/activejob/test/integration/queuing_test.rb#L62 |
ccc8b61
to
ff59074
Compare
@rafaelfranca ok man, done! I've added a test and CI is green now |
Fix accessing provider_job_id inside active jobs for sidekiq adapter
Backported in cbe752f |
I know this is an old issue, but I noticed that |
Accessing
provider_job_id
attribute inside a job using sidekiq adapter always returnsnil
. I looked atSidekiqAdapter
class insideActiveJob
, and it looks like that enqueue method here already fire the job before assigning its id tojob.provider_job_id
.I need to access it so I can use
Sidekiq::Status
tracking-progress methods. The basic idea behind these methods is to store the progress using thejid
attribute withinSidekiq::Worker
. So insideActiveJob
while we don't have access to thatjid
attribute, we can easily work around that by using abefore_perform
callback like thatbut the problem now, is that
provider_job_id
always returnsnil
.so I fixed this by merging the
jid
to thejob_data
insideJobWrapper#perform
method, and then assigning it insidedeserialize
method.