FEATURE: readonly safeguard

This commit is contained in:
Régis Hanol 2015-02-11 21:50:17 +01:00
parent db53e022cc
commit 9a637836d0

View file

@ -170,13 +170,24 @@ module Discourse
end end
def self.enable_readonly_mode def self.enable_readonly_mode
$redis.set readonly_mode_key, 1 $redis.set(readonly_mode_key, 1)
MessageBus.publish(readonly_channel, true) MessageBus.publish(readonly_channel, true)
keep_readonly_mode
true true
end end
def self.keep_readonly_mode
# extend the expiry by 1 minute every 30 seconds
Thread.new do
while readonly_mode?
$redis.expire(readonly_mode_key, 1.minute)
sleep 30.seconds
end
end
end
def self.disable_readonly_mode def self.disable_readonly_mode
$redis.del readonly_mode_key $redis.del(readonly_mode_key)
MessageBus.publish(readonly_channel, false) MessageBus.publish(readonly_channel, false)
true true
end end