john seymour
john seymour

Reputation: 213

Rails jobs and Sidekiq

Ive just installed redis and sidekiq on my app,

I Have a job to update a field on the users table when called upon,

And a job that sends an email once a week to all users.

Now if i boot up sidekiq with bundle exec sidekiq The job to update the users field fires off and completes but the email job stays in the enqueued section.

But if i boot it up with bundle exec sidekiq -q workers -q mailers Which i got from the Sidekiq github page only the mail jobs get completed and the others stay in the enqueued section.

Is there a command to be able to run both? Ive only started to learn about sidekiq and redis yesterday so sorry if this a stupid question,

I have the activejob.que_adaptar set to sidekiq in application.rb.

This is how i have my sidekiq worker for the User job set up:

class DeactivateUser
 include Sidekiq::Worker

  def perform
   User.active.update_all(active: false)
  end

end

Thanks.

Upvotes: 3

Views: 2423

Answers (2)

SV Madhava Reddy
SV Madhava Reddy

Reputation: 2018

As Oskar configured, follow the same approach to have multiple queues processed by single sidekiq process. In addition, you have to mention the queue name in the worker file. So that the sidekiq process will get the jobs from redis of that queue. For ex: ( sidekiq_options queue: :mailers )

class WORKER_NAME
  include Sidekiq::Worker
  sidekiq_options queue: :<queue_name>

   def perform
     ... # your work
   end
end

If you want to start process only listening to one queue mailers and having concurrency 10, please start like this.

bundle exec sidekiq -c 10 -C config/myapp_sidekiq.yml -q mailers -q queue1 -q queue2

This will listen to total of 3 queues named mailers, queue1, queue2. This is how you will have to start the sidekiq. For more documentation, please refer to this.

Upvotes: 1

Oskar
Oskar

Reputation: 43

Create config/sidekiq.yml with list of your queues and run sidekiq -C config/sidekiq.yml.

    #config/sidekiq.yml

    ---
    :concurrency: 5
    :queues:
      - default
      - mailers
      - orders

Upvotes: 2

Related Questions