Add ENV variable to only allow Sidekiq scheduler to run on a particular host.

This commit is contained in:
Guo Xiang Tan 2017-04-26 14:13:26 +08:00
parent c3b5bca0e8
commit f499180bb3
1 changed files with 17 additions and 14 deletions

View File

@ -15,7 +15,6 @@ Sidekiq.configure_server do |config|
end end
if Sidekiq.server? if Sidekiq.server?
# warm up AR # warm up AR
RailsMultisite::ConnectionManagement.each_connection do RailsMultisite::ConnectionManagement.each_connection do
(ActiveRecord::Base.connection.tables - %w[schema_migrations]).each do |table| (ActiveRecord::Base.connection.tables - %w[schema_migrations]).each do |table|
@ -24,6 +23,9 @@ if Sidekiq.server?
end end
Rails.application.config.after_initialize do Rails.application.config.after_initialize do
scheduler_hostname = ENV["UNICORN_SCHEDULER_HOSTNAME"]
if !scheduler_hostname || scheduler_hostname == `hostname`.strip
require 'scheduler/scheduler' require 'scheduler/scheduler'
manager = Scheduler::Manager.new manager = Scheduler::Manager.new
Scheduler::Manager.discover_schedules.each do |schedule| Scheduler::Manager.discover_schedules.each do |schedule|
@ -41,6 +43,7 @@ if Sidekiq.server?
end end
end end
end end
end
end end
Sidekiq.logger.level = Logger::WARN Sidekiq.logger.level = Logger::WARN