问题
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.
回答1:
The Sidekiq Dynamic Queues gem will probably help you.
回答2:
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
来源:https://stackoverflow.com/questions/20133346/how-can-i-create-sidekiq-queues-with-variable-names-at-runtime