Add ENV variable to only allow Sidekiq scheduler to run on a particular host.
This commit is contained in:
parent
c3b5bca0e8
commit
f499180bb3
|
@ -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,20 +23,24 @@ if Sidekiq.server?
|
||||||
end
|
end
|
||||||
|
|
||||||
Rails.application.config.after_initialize do
|
Rails.application.config.after_initialize do
|
||||||
require 'scheduler/scheduler'
|
scheduler_hostname = ENV["UNICORN_SCHEDULER_HOSTNAME"]
|
||||||
manager = Scheduler::Manager.new
|
|
||||||
Scheduler::Manager.discover_schedules.each do |schedule|
|
if !scheduler_hostname || scheduler_hostname == `hostname`.strip
|
||||||
manager.ensure_schedule!(schedule)
|
require 'scheduler/scheduler'
|
||||||
end
|
manager = Scheduler::Manager.new
|
||||||
Thread.new do
|
Scheduler::Manager.discover_schedules.each do |schedule|
|
||||||
while true
|
manager.ensure_schedule!(schedule)
|
||||||
begin
|
end
|
||||||
manager.tick
|
Thread.new do
|
||||||
rescue => e
|
while true
|
||||||
# the show must go on
|
begin
|
||||||
Discourse.handle_job_exception(e, {message: "While ticking scheduling manager"})
|
manager.tick
|
||||||
|
rescue => e
|
||||||
|
# the show must go on
|
||||||
|
Discourse.handle_job_exception(e, {message: "While ticking scheduling manager"})
|
||||||
|
end
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
sleep 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue