Class: RR::ReplicationRun
- Inherits:
-
Object
- Object
- RR::ReplicationRun
- Defined in:
- lib/rubyrep/replication_run.rb
Overview
Executes a single replication run
Instance Attribute Summary collapse
-
#session ⇒ Object
The current Session object.
Instance Method Summary collapse
-
#helper ⇒ Object
Returns the current ReplicationHelper; creates it if necessary.
-
#initialize(session) ⇒ ReplicationRun
constructor
Creates a new ReplicationRun instance.
-
#replicator ⇒ Object
Returns the current replicator; creates it if necessary.
-
#run ⇒ Object
Executes the replication run.
Constructor Details
#initialize(session) ⇒ ReplicationRun
Creates a new ReplicationRun instance.
-
session: the current Session
55 56 57 |
# File 'lib/rubyrep/replication_run.rb', line 55 def initialize(session) self.session = session end |
Instance Attribute Details
#session ⇒ Object
The current Session object
9 10 11 |
# File 'lib/rubyrep/replication_run.rb', line 9 def session @session end |
Instance Method Details
#helper ⇒ Object
Returns the current ReplicationHelper; creates it if necessary
12 13 14 |
# File 'lib/rubyrep/replication_run.rb', line 12 def helper @helper ||= ReplicationHelper.new(self) end |
#replicator ⇒ Object
Returns the current replicator; creates it if necessary.
17 18 19 20 |
# File 'lib/rubyrep/replication_run.rb', line 17 def replicator @replicator ||= Replicators.replicators[session.configuration.[:replicator]].new(helper) end |
#run ⇒ Object
Executes the replication run.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubyrep/replication_run.rb', line 23 def run return unless [:left, :right].any? do |database| Timeout::timeout(session.configuration.[:database_connection_timeout]) do session.send(database).select_one( "select id from #{session.configuration.[:rep_prefix]}_pending_changes" ) != nil end end begin success = false replicator # ensure that replicator is created and has chance to validate settings loop do begin session.reload_changes # ensure the cache of change log records is up-to-date diff = ReplicationDifference.new session diff.load break unless diff.loaded? replicator.replicate_difference diff if diff.type != :no_diff rescue Exception => e helper.log_replication_outcome diff, e., e.class.to_s + "\n" + e.backtrace.join("\n") end end success = true # considered to be successful if we get till here ensure helper.finalize success end end |