FIX: `Discourse.keep_readonly_mode` spins a new thread each time it is called.
This commit is contained in:
parent
6e97242bb9
commit
34e4c8f573
|
@ -294,7 +294,12 @@ module Discourse
|
||||||
def self.keep_readonly_mode(key)
|
def self.keep_readonly_mode(key)
|
||||||
# extend the expiry by 1 minute every 30 seconds
|
# extend the expiry by 1 minute every 30 seconds
|
||||||
unless Rails.env.test?
|
unless Rails.env.test?
|
||||||
Thread.new do
|
@threads ||= {}
|
||||||
|
|
||||||
|
active_thread = @threads[key]
|
||||||
|
|
||||||
|
unless active_thread&.alive?
|
||||||
|
@threads[key] = Thread.new do
|
||||||
while readonly_mode?(key)
|
while readonly_mode?(key)
|
||||||
$redis.expire(key, READONLY_MODE_KEY_TTL)
|
$redis.expire(key, READONLY_MODE_KEY_TTL)
|
||||||
sleep 30.seconds
|
sleep 30.seconds
|
||||||
|
@ -302,6 +307,7 @@ module Discourse
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.disable_readonly_mode(key = READONLY_MODE_KEY)
|
def self.disable_readonly_mode(key = READONLY_MODE_KEY)
|
||||||
$redis.del(key)
|
$redis.del(key)
|
||||||
|
|
Loading…
Reference in New Issue