Ram Laxman Yadav bio photo

Ram Laxman Yadav

Ruby on Rails Developer

Email Twitter LinkedIn Github Stackoverflow

Hello Friends, I am back with new real programming problem. In general practice when we are working with sidekiq and delayed jobs. The problem occurs when we want custom queue with custom sidekiq workers. In this blog I am going to discuss the same with an example Here we go:

Create Sidekiq worker:

You can create sidekiq worker class if you want that the jobs will perform by this class. This is not mandatory. Create a worker class inside app/worker/worker_name.rb.

class WorkerName

  include Sidekiq::Worker
  sidekiq_options queue: 'YOUR_QUEUE_NAME' 
  # you can add queue name here or just pass it as param when calling perform method

  def perform(params)
   # your code to perform in delayed jobs
  end
end

Now you have a worker class that will pick the jobs from queue YOUR_QUEUE_NAME.

Add queue name inside config/sidekiq.yml file:

Add YOUR_QUEUE_NAME inside config/sidekiq.yml file with weight. As like:

---
:concurrency: 4
staging:
  :concurrency: 4
production:
  :concurrency: 10
:queues:
  - [queue1, 1]
  - [queue2, 2]
  - [YOUR_QUEUE_NAME, 3]
  - default

Sidekiq check high weight queue first.

Adding sidekiq process to the queue

If you want to add dedicated sidekiq worker instance to the particular queue, so that This worker instance can handle jobs from the queueYOUR_QUEUE_NAME, then you can just add your Procfile

  • sidekiq -q YOUR_QUEUE_NAME

remove YOUR_QUEUE_NAME from your config/sidekiq.yml file, Otherwise other instance will also start executing jobs from YOUR_QUEUE_NAME queue.

  • sidekiq -C config/sidekiq.yml

To start sidekiq process for other queues. Thanks for reading for more documentation, Please refer the link