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

Conversation

Projects
None yet
5 participants
@mu29
Copy link
Contributor

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

This comment has been minimized.

Copy link

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.

@maclover7 maclover7 added the activejob label Aug 18, 2016

@@ -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)

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 19, 2016

Member

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

This comment has been minimized.

@mu29

mu29 Aug 19, 2016

Contributor

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

View changes

activejob/test/integration/queuing_test.rb Outdated
@@ -43,6 +43,15 @@ class QueuingTest < ActiveSupport::TestCase
end
end

test "resque JobWrapper should have instance variable queue" do
skip unless adapter_is?(:resque)
Sidekiq::Testing.inline! do

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 19, 2016

Member

Does it needs to use sidekiq here? It should skip this test if the adapter is no resque.

This comment has been minimized.

@mu29

mu29 Aug 19, 2016

Contributor

I fixed it just now. sorry!

@rafaelfranca

This comment has been minimized.

Copy link
Member

rafaelfranca commented Aug 19, 2016

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

@mu29 mu29 force-pushed the pedaling:fix/active-job-resque branch Aug 19, 2016

@mu29

This comment has been minimized.

Copy link
Contributor

mu29 commented Aug 19, 2016

Done! Thank you!

@mu29 mu29 force-pushed the pedaling:fix/active-job-resque branch 3 times, most recently Aug 19, 2016

Added instance variable `@Queue` to JobWrapper.
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 pedaling:fix/active-job-resque branch to 9f6461a Aug 19, 2016

@mu29

This comment has been minimized.

Copy link
Contributor

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

codeclimate Code Climate has skipped analysis of this commit.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

rafaelfranca added a commit that referenced this pull request Aug 23, 2016

rafaelfranca added a commit that referenced this pull request Aug 23, 2016

@rafaelfranca

This comment has been minimized.

Copy link
Member

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