Reputation: 138
I am trying to create queues with variable queue names.
queue_name = "guide_" + guide['id'].to_s
Sidekiq::Client.push({
'class' => GuidePdfWorker,
'queue' => queue_name,
'args' => [key],
'backtrace' => true
})
I know that I am supposed to add them to config/sidekiq.yml, but I can't, since I don't know the value of queue_name.
When I log Sidekiq::Client.registered_queues()
I can see my queues, but they are never processed.
Upvotes: 6
Views: 7907
Reputation: 1066
The gem suggested by the accepted answer hasn't received any updates in the last nine years. I found the gem sidekiq_limit-fetch backed by Evil Martians and just verified that it supports dynamic queues that do not have to be specified when Sidekiq starts.
Check out the dynamic queues option. Now you can do
SomeWorker.set(queue: "your-dynamic-queue").perform_async(args)
Sidekiq will fetch this job from the "your-dynamic-queue" queue and execute it.
Upvotes: 0
Reputation: 16727
Just to provide a more complete, updated answer: there are plugins and extensions to Sidekiq that can do things like this, but Sidekiq is not designed to operate this way.
I don't recommend having more than a handful of queues ... and Sidekiq Pro cannot reliably handle multiple queues without polling
https://github.com/mperham/sidekiq/wiki/Advanced-Options#queues
the number of named queues used should be minimized.
https://github.com/mperham/sidekiq/issues/835
Instead, consider having a known, static, queue with a worker that dispatches based on what you'd like to be dynamic:
class GuidePdfWorker
include Sidekiq::Worker
sidekiq_options queue: 'default'
def perform(guide)
# branch on guide['id'], perhaps re-queue in higher or lower priority queue?
end
end
Upvotes: 0