简体   繁体   中英

Sidekiq with a Worker who fetches jobs from two queues

I would like a Worker to be able to fetch jobs from two queues, which each queue has a diferent priority.

Right now, my worker looks like this:

class OrderWorker
  include Sidekiq::Worker
  sidekiq_options retry: false, queue: :orders
end

But I want to have another queue with orders that have higher priority, and make the worker consume that other queue. Is that even possible with Sidekiq? If so, at the time that you do OrderWorker.perform_async(...) , how do you specify which queue?

Thanks!

You can pass queue as an option:

OrderWorker.perform_async(:queue => 'high')
OrderWorker.perform_async(:queue => 'default') # default is 'default' anyway

perform_async and perform_in call method push , which has a queue argument among others.

To be honest I don't know if sidekiq supports this, but if it was me, I'd probably just use inheritance for this since it's just plain Ruby.

class OrderWorker
  include Sidekiq::Worker
end

class HighPriorityOrderWorker < OrderWorker
  sidekiq_options retry: false, queue: :high_priority_orders
end

class LowPriorityOrderWorker < OrderWorker
  sidekiq_options retry: false, queue: :low_priority_orders
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM