How can I create sidekiq queues with variable names at runtime?

女生的网名这么多〃 提交于 2019-12-10 20:15:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!