FIX: queue heartbeats in readonly modes

If sidekiq is paused or Discourse is in readonly continue to queue
heartbeats

If we do not do that then a master process can end up reaping sidekiq
workers and causing various badness

This also impacts restore which can do weird stuff TM in cases like this
This commit is contained in:
Sam 2018-08-29 12:36:59 +10:00
parent 7516f5159e
commit 44cf3cf975
4 changed files with 48 additions and 3 deletions

View File

@ -183,8 +183,9 @@ module Jobs
extend MiniScheduler::Schedule
def perform(*args)
return if Discourse.readonly_mode?
super
if (Jobs::Heartbeat === self) || !Discourse.readonly_mode?
super
end
end
end

View File

@ -74,7 +74,7 @@ class Sidekiq::Pausable
end
def call(worker, msg, queue)
if Sidekiq.paused?
if Sidekiq.paused? && !(Jobs::RunHeartbeat === worker)
worker.class.perform_in(@delay, *msg['args'])
else
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)

View File

@ -2,10 +2,35 @@ require 'rails_helper'
require_dependency 'sidekiq/pausable'
describe Sidekiq do
after do
Sidekiq.unpause!
end
it "can pause and unpause" do
Sidekiq.pause!
expect(Sidekiq.paused?).to eq(true)
Sidekiq.unpause!
expect(Sidekiq.paused?).to eq(false)
end
it "can still run heartbeats when paused" do
Sidekiq.pause!
freeze_time 1.week.from_now
jobs = Sidekiq::ScheduledSet.new
Sidekiq::Testing.disable! do
jobs.clear
middleware = Sidekiq::Pausable.new
middleware.call(Jobs::RunHeartbeat.new, { "args" => [{}] }, "critical") do
"done"
end
jobs = Sidekiq::ScheduledSet.new
expect(jobs.size).to eq(0)
end
end
end

View File

@ -0,0 +1,19 @@
require 'rails_helper'
require_dependency 'jobs/base'
describe Jobs::Heartbeat do
after do
Discourse.disable_readonly_mode
end
it "still enqueues heartbeats in readonly mode" do
freeze_time 1.week.from_now
Discourse.enable_readonly_mode
Sidekiq::Testing.inline! do
Jobs::Heartbeat.new.perform(nil)
expect(Jobs::RunHeartbeat.last_heartbeat).to eq(Time.new.to_i)
end
end
end