问题
I know we can do:
sidekiq_options queue: "Foo"
But in this case it's the Worker which is assigned to only one queue: "Foo".
I need to assign a Job (and not a Worker) in specific queue. With Resque it's easy:
Resque.enqueue_to(queue_name, my_job)
Further, for concurrency problem, i need to limit the number of Worker on each queue at 1.
How can I do this?
回答1:
You might use https://github.com/brainopia/sidekiq-limit_fetch
and then:
Sidekiq::Client.push({
'class' => GuidePdfWorker,
'queue' => queue_name,
'args' => [my_job]
})
Sidekiq::Queue[queue_name].limit = 1
But you have to declare your queue_name in the config/sidekiq.yml
回答2:
I did fork the gem and modified to work with dynamic queues, made the pull request but I am waiting merge. But in my business I use my gem, which follows below.
https://github.com/dlanileonardo/sidekiq-limit_fetch
Only put my gem in Gemfile:
gem 'sidekiq-limit_fetch', :git => 'https://github.com/dlanileonardo/sidekiq-limit_fetch.git'
(Sorry I Dont speak English)
If my pull request status is Merged, update the original gem, the unit tests is passed.
https://github.com/brainopia/sidekiq-limit_fetch/pull/46
回答3:
I have achieved the above said functionality using the sidekiq limit fetch. You can set dynamic queue mode
to true and specify the queues in the Sidekiq::Client.push
And set the process limit
to the specific queue. We can either set the process limit or we can ignore and simply it process as per the sidekiq default limit
来源:https://stackoverflow.com/questions/20080047/how-to-push-job-in-specific-queue-and-limit-number-workers-with-sidekiq