FIX: Discourse.keep_readonly_mode spins a new thread each time it is called.

This commit is contained in:
Guo Xiang Tan 2018-06-19 10:15:29 +08:00
parent 6e97242bb9
commit 34e4c8f573

View File

@ -294,10 +294,16 @@ module Discourse
def self.keep_readonly_mode(key)
# extend the expiry by 1 minute every 30 seconds
unless Rails.env.test?
Thread.new do
while readonly_mode?(key)
$redis.expire(key, READONLY_MODE_KEY_TTL)
sleep 30.seconds
@threads ||= {}
active_thread = @threads[key]
unless active_thread&.alive?
@threads[key] = Thread.new do
while readonly_mode?(key)
$redis.expire(key, READONLY_MODE_KEY_TTL)
sleep 30.seconds
end
end
end
end