lib/rubyrep/replication_run.rb in rubyrep-1.0.7 vs lib/rubyrep/replication_run.rb in rubyrep-1.0.8
- old
+ new
@@ -33,31 +33,46 @@
end
t.join session.configuration.options[:database_connection_timeout]
changes_pending
end
+ # Apparently sometimes above check for changes takes already so long, that
+ # the replication run times out.
+ # Check for this and if timed out, return (silently).
+ return if sweeper.terminated?
+
loaders = LoggedChangeLoaders.new(session)
+ success = false
begin
- success = false
replicator # ensure that replicator is created and has chance to validate settings
loop do
begin
loaders.update # ensure the cache of change log records is up-to-date
diff = ReplicationDifference.new loaders
diff.load
break unless diff.loaded?
- raise "Replication run timed out" if sweeper.terminated?
+ break if sweeper.terminated?
replicator.replicate_difference diff if diff.type != :no_diff
rescue Exception => e
- helper.log_replication_outcome diff, e.message,
- e.class.to_s + "\n" + e.backtrace.join("\n")
+ begin
+ helper.log_replication_outcome diff, e.message,
+ e.class.to_s + "\n" + e.backtrace.join("\n")
+ rescue Exception => _
+ # if logging to database itself fails, re-raise the original exception
+ raise e
+ end
end
end
- success = true # considered to be successful if we get till here
+ success = true
ensure
- helper.finalize success
+ if sweeper.terminated?
+ helper.finalize false
+ session.disconnect_databases
+ else
+ helper.finalize success
+ end
end
end
# Installs the current sweeper into the database connections
def install_sweeper