Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq - Prevent worker from being executed in specific machine

I'm working on a Rails project that uses Sidekiq. Our Sidekiq implementation has two workers (WorkerA, that reads queue_a, and WorkerB, which reads queue_b). One of them has to be executed in the same server the Rails app is and the other one in a different server(s). How can I prevent WorkerB from being executed in the first server, and vice versa? Can a Sidekiq process be configured to run just specific workers?

EDIT: The Redis server is in the same machine the Rails app is.

like image 874
davids Avatar asked Nov 26 '25 20:11

davids


1 Answers

Use a hostname-specific queue. config/sidekiq.yml:

---
:verbose: false
:concurrency: 25
:queues:
  - default
  - <%= `hostname`.strip %>

In your worker:

class ImageUploadProcessor
  include Sidekiq::Worker
  sidekiq_options queue: `hostname`.strip

  def perform(filename)
    # process image
  end
end

More detail on my blog:

http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/

like image 158
Mike Perham Avatar answered Nov 29 '25 14:11

Mike Perham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!