Search code examples
rubyresquejobssidekiqworker

How to push job in specific queue and limit number workers with sidekiq?


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?


Solution

  • 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