FIX: Forking prevented notifications from being sent after backup

This is a workaround for https://github.com/rubyjs/mini_racer/issues/175
This commit is contained in:
Gerhard Schlager 2020-09-18 17:29:43 +02:00
parent cc2a306936
commit 76477a1c8b
2 changed files with 45 additions and 45 deletions

View File

@ -12,29 +12,18 @@ module BackupRestore
if opts[:fork] == false
BackupRestore::Backuper.new(user_id, opts).run
else
start! BackupRestore::Backuper.new(user_id, opts)
spawn_process!(:backup, user_id, opts)
end
end
def self.restore!(user_id, opts = {})
restorer = BackupRestore::Restorer.new(
user_id: user_id,
filename: opts[:filename],
factory: BackupRestore::Factory.new(
user_id: user_id,
client_id: opts[:client_id]
),
disable_emails: opts.fetch(:disable_emails, true)
)
start! restorer
spawn_process!(:restore, user_id, opts)
end
def self.rollback!
raise BackupRestore::OperationRunningError if BackupRestore.is_operation_running?
if can_rollback?
move_tables_between_schemas("backup", "public")
after_fork
end
end
@ -181,39 +170,12 @@ module BackupRestore
"start_logs_message_id"
end
def self.start!(runner)
child = fork do
begin
after_fork
runner.run
rescue Exception => e
puts "--------------------------------------------"
puts "---------------- EXCEPTION -----------------"
puts e.message
puts e.backtrace.join("\n")
puts "--------------------------------------------"
ensure
begin
clear_shutdown_signal!
rescue Exception => e
puts "============================================"
puts "================ EXCEPTION ================="
puts e.message
puts e.backtrace.join("\n")
puts "============================================"
ensure
exit!(0)
end
end
end
def self.spawn_process!(type, user_id, opts)
script = File.join(Rails.root, "script", "spawn_backup_restore.rb")
command = ["bundle", "exec", "ruby", script, type, user_id, opts.to_json].shelljoin
Process.detach(child)
true
end
def self.after_fork
Discourse.after_fork
pid = spawn(command)
Process.detach(pid)
end
def self.backup_tables_count

View File

@ -0,0 +1,38 @@
# frozen_string_literal: true
# This script is used by BackupRestore.backup! and BackupRestore.restore!
require File.expand_path("../../config/environment", __FILE__)
def backup
user_id, opts = parse_params
BackupRestore::Backuper.new(user_id, opts).run
end
def restore
user_id, opts = parse_params
BackupRestore::Restorer.new(
user_id: user_id,
filename: opts[:filename],
factory: BackupRestore::Factory.new(
user_id: user_id,
client_id: opts[:client_id]
),
disable_emails: opts.fetch(:disable_emails, true)
).run
end
def parse_params
user_id = ARGV[1].to_i
opts = JSON.parse(ARGV[2], symbolize_names: true)
[user_id, opts]
end
case ARGV[0]
when "backup"
backup
when "restore"
restore
else
raise "Unknown argument: #{ARGV[0]}"
end