Allow a sidekiq queue to be configured to only run on a certain hostname.

This commit is contained in:
Guo Xiang Tan 2017-04-27 15:28:23 +08:00
parent b755279cf0
commit 84490c4558

View File

@ -31,8 +31,19 @@ class Demon::Sidekiq < Demon::Base
# parent process is in charge of the file anyway.
Sidekiq::Logging.logger = nil
cli = Sidekiq::CLI.instance
cli.parse(["-c", GlobalSetting.sidekiq_workers.to_s, "-q", "critical,4", "-q", "default,2", "-q", "low"])
options = ["-c", GlobalSetting.sidekiq_workers.to_s]
[['critical', 4], ['default', 2], ['low', 1]].each do |queue_name, weight|
custom_queue_hostname = ENV["UNICORN_SIDEKIQ_#{queue_name.upcase}_QUEUE_HOSTNAME"]
if !custom_queue_hostname || custom_queue_hostname == `hostname`.strip
options << "-q"
options << "#{queue_name},#{weight}"
end
end
cli.parse(options)
load Rails.root + "config/initializers/100-sidekiq.rb"
cli.run
rescue => e