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?
Sidekiq is an open-source framework that provides efficient background processing for Ruby applications. It uses Redis as an in-memory data structure to store all of its job and operational data. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs.
Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so your jobs and workers have the full Rails API, including Active Record, available for use. The server will instantiate the worker and call perform with the given arguments.
Today Sidekiq uses a default concurrency of 25. These means Sidekiq will spawn 25 worker threads and execute up to 25 jobs concurrently in a process.
Out-of-the-box Sidekiq uses a single queue named "default," but it's possible to create and use any number of other named queues if there is at least one Sidekiq worker configured to look at every queue.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With