FIX: disable scheduled jobs when in readonly mode

This commit is contained in:
Régis Hanol 2016-01-11 18:31:28 +01:00
parent 19c630e7c2
commit fbacaab2fc
3 changed files with 7 additions and 6 deletions

View file

@ -197,6 +197,11 @@ module Jobs
class Scheduled < Base
extend Scheduler::Schedule
def perform(*args)
return if Discourse.readonly_mode?
super
end
end
def self.enqueue(job_name, opts={})

View file

@ -10,7 +10,6 @@ module Scheduler
class Manager
attr_accessor :random_ratio, :redis
class Runner
def initialize(manager)
@mutex = Mutex.new
@ -157,7 +156,6 @@ module Scheduler
lock do
schedule_info(klass).schedule!
end
end
def remove(klass)
@ -203,8 +201,8 @@ module Scheduler
def schedule_next_job(hostname=nil)
(key, due), _ = redis.zrange Manager.queue_key(hostname), 0, 0, withscores: true
return unless key
if due.to_i <= Time.now.to_i
klass = get_klass(key)
unless klass

View file

@ -68,15 +68,13 @@ end
# server middleware that will reschedule work whenever Sidekiq is paused
class Sidekiq::Pausable
attr_reader :delay
def initialize(delay = 5.seconds)
@delay = delay
end
def call(worker, msg, queue)
if Sidekiq.paused?
worker.class.perform_in(delay, *msg['args'])
worker.class.perform_in(@delay, *msg['args'])
else
yield
end