diff --git a/script/training_db_sync.rb b/script/training_db_sync.rb index 38e5c6a20..b4e90b9d6 100644 --- a/script/training_db_sync.rb +++ b/script/training_db_sync.rb @@ -63,14 +63,26 @@ def capture_data_from_source --no-owner CMD Kernel.puts "Running pg_dump on #{source} ==> #{cmd}" - CmdRunner.run(cmd) + begin + CmdRunner.run(cmd) + rescue => e + clear_sessions + remove_temp_files + raise e + end end def copy_data_to_destination authenticate_to(destination) cmd = %(cat #{data_filename} | cf ssh beis-roda-#{destination} -c "cat > #{data_filename}") Kernel.puts "Copying data to #{destination} ==> #{cmd}" - CmdRunner.run(cmd) + begin + CmdRunner.run(cmd) + rescue => e + clear_sessions + remove_temp_files + raise e + end end def load_source_data_to_destination @@ -80,7 +92,13 @@ def load_source_data_to_destination psql < #{data_filename} CMD Kernel.puts "Loading data from #{source} to #{destination} ==> #{cmd}" - CmdRunner.run(cmd) + begin + CmdRunner.run(cmd) + rescue => e + clear_sessions + remove_temp_files + raise e + end end def force_password_reset_for_users @@ -138,13 +156,11 @@ class CmdRunner require "open3" def self.run(command) - begin - stdout, _stderr, _status = Open3.capture3(command) - rescue => error - raise "'#{command}' failed (#{error})" - end + _stdout, stderr, _status = Open3.capture3(command) - Kernel.puts stdout.chomp + if stderr + raise StandardError.new("Command: '#{command}' FAILED with error: '#{stderr}'") + end end end end