mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08:00
FIX: Backup/Restore didn't use correct Redis namespace in multisite (#18060)
In a multisite Discourse reported that no backup is running after 60 seconds because the Redis key expired. Also, the thread that listens for a shutdown signal stopped running immediately because it didn't detect a running operation.
This commit is contained in:
parent
935609172a
commit
9ff13cee14
|
@ -144,12 +144,18 @@ module BackupRestore
|
|||
end
|
||||
|
||||
def self.keep_it_running
|
||||
db = RailsMultisite::ConnectionManagement.current_db
|
||||
|
||||
# extend the expiry by 1 minute every 30 seconds
|
||||
Thread.new do
|
||||
# this thread will be killed when the fork dies
|
||||
while true
|
||||
Discourse.redis.expire(running_key, 1.minute)
|
||||
sleep 30.seconds
|
||||
RailsMultisite::ConnectionManagement.with_connection(db) do
|
||||
Thread.current.name = "keep_op_running"
|
||||
|
||||
# this thread will be killed when the fork dies
|
||||
while true
|
||||
Discourse.redis.expire(running_key, 1.minute)
|
||||
sleep 30.seconds
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,9 +98,13 @@ module BackupRestore
|
|||
BackupRestore.clear_shutdown_signal!
|
||||
|
||||
Thread.new do
|
||||
while BackupRestore.is_operation_running?
|
||||
exit if BackupRestore.should_shutdown?
|
||||
sleep 0.1
|
||||
Thread.current.name = "shutdown_wait"
|
||||
|
||||
RailsMultisite::ConnectionManagement.with_connection(@current_db) do
|
||||
while BackupRestore.is_operation_running?
|
||||
exit if BackupRestore.should_shutdown?
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,9 +47,13 @@ module BackupRestore
|
|||
BackupRestore.clear_shutdown_signal!
|
||||
|
||||
Thread.new do
|
||||
while BackupRestore.is_operation_running?
|
||||
exit if BackupRestore.should_shutdown?
|
||||
sleep 0.1
|
||||
Thread.current.name = "shutdown_wait"
|
||||
|
||||
RailsMultisite::ConnectionManagement.with_connection(@current_db) do
|
||||
while BackupRestore.is_operation_running?
|
||||
exit if BackupRestore.should_shutdown?
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,4 +36,21 @@ RSpec.describe BackupRestore::SystemInterface, type: :multisite do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#listen_for_shutdown_signal" do
|
||||
it "uses the correct Redis namespace" do
|
||||
test_multisite_connection("second") do
|
||||
BackupRestore.mark_as_running!
|
||||
|
||||
expect do
|
||||
thread = subject.listen_for_shutdown_signal
|
||||
BackupRestore.set_shutdown_signal!
|
||||
thread.join
|
||||
end.to raise_error(SystemExit)
|
||||
|
||||
BackupRestore.clear_shutdown_signal!
|
||||
BackupRestore.mark_as_not_running!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user