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

Add @queue variable to JobWrapper #26205

Merged
merged 1 commit into from Aug 23, 2016
Merged

Conversation

@mu29
Copy link
Contributor

@mu29 mu29 commented Aug 18, 2016

Fix errors when using resque-scheduler's #enqueue_delayed_selection method.

In resque-scheduler, #enqueue_delayed_selection, or remove_delayed use #job_to_hash to pick item in redis list.

def job_to_hash(klass, args)
  { class: klass.to_s, args: args, queue: queue_from_class(klass) }
end

This method call #queue_from_class

def queue_from_class(klass)
  klass.instance_variable_get(:@queue) ||
    (klass.respond_to?(:queue) and klass.queue)
end

However, current JobWrapper class does not have instance variable @queue, so the return value of #job_to_hash method is not equal to redis item that we want to catch. As a result, we cannot use #enqueue_delayed_selection, or remove_delayed method when our job extends ActiveJob.
I just put instance variable @queue to JobWrapper class.

@rails-bot
Copy link

@rails-bot rails-bot commented Aug 18, 2016

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.

@@ -27,6 +27,7 @@ module QueueAdapters
# Rails.application.config.active_job.queue_adapter = :resque
class ResqueAdapter
def enqueue(job) #:nodoc:
JobWrapper.instance_variable_set(:@queue, job.queue_name)
Copy link
Member

@rafaelfranca rafaelfranca Aug 19, 2016

We should change JobWrapper to be an instance and set this at initialization time. Also could you add a test to this behavior?

Copy link
Contributor Author

@mu29 mu29 Aug 19, 2016

Thank you for comment, but in resque, they make frequent use of #constantize method that needs JobWrapper class. So I decided to keep JobWrapper class singleton. Sorry :(

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 19, 2016

Awesome! Could you add a CHANGELOG entry and squash your commits?

@mu29 mu29 force-pushed the fix/active-job-resque branch from fee13c4 to a322d0e Aug 19, 2016
@mu29
Copy link
Contributor Author

@mu29 mu29 commented Aug 19, 2016

Done! Thank you!

@mu29 mu29 force-pushed the fix/active-job-resque branch 3 times, most recently from 22358a1 to 21c1c19 Aug 19, 2016
This will fix issues in [resque-scheduler](https://github.com/resque/resque-scheduler) `#job_to_hash` method,
so we can use `#enqueue_delayed_selection`, `#remove_delayed` method in resque-scheduler smoothly.
@mu29 mu29 force-pushed the fix/active-job-resque branch from 21c1c19 to 9f6461a Aug 19, 2016
@mu29
Copy link
Contributor Author

@mu29 mu29 commented Aug 19, 2016

Travis build passed after several tries! :) @rafaelfranca

@rafaelfranca rafaelfranca merged commit 9f6461a into rails:master Aug 23, 2016
2 checks passed
rafaelfranca added a commit that referenced this issue Aug 23, 2016
rafaelfranca added a commit that referenced this issue Aug 23, 2016
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 23, 2016

Backported in e0313a2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants