Created
April 10, 2015 12:42
-
-
Save gma/615727d13838db797a06 to your computer and use it in GitHub Desktop.
How I might try changing a Sidekiq queue in a rake task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This obviously isn't thread safe, but I bet that doesn't matter a monkeys | |
| # if you're running it in a rake task. | |
| # | |
| # Also, I don't use Sidekiq, so I might have misunderstood how to use the API | |
| # in a fundamental manner which could mean that what follows is useless... | |
| def with_queue(job_class, queue_name, &block) | |
| default_queue = job_class.get_sidekick_options.fetch(:queue) | |
| job_class.sidekick_options(queue: queue_name) | |
| yield | |
| ensure | |
| job_class.sidekick_options(queue: default_queue) | |
| end | |
| task :foo do | |
| with_queue(MyWorker, 'the-queue') do | |
| MyWorker.perform(...) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment