Skip to content

Instantly share code, notes, and snippets.

@gma
Created April 10, 2015 12:42
Show Gist options
  • Select an option

  • Save gma/615727d13838db797a06 to your computer and use it in GitHub Desktop.

Select an option

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