lib/rubyrep/replication_run.rb in rubyrep-1.0.9 vs lib/rubyrep/replication_run.rb in rubyrep-1.1.0
- old
+ new
@@ -20,10 +20,27 @@
def replicator
@replicator ||=
Replicators.replicators[session.configuration.options[:replicator]].new(helper)
end
+ # Calls the event filter for the give difference.
+ # * +diff+: instance of ReplicationDifference
+ # Returns +true+ if replication of the difference should *not* proceed.
+ def event_filtered?(diff)
+ event_filter = helper.options_for_table(diff.changes[:left].table)[:event_filter]
+ if event_filter && event_filter.respond_to?(:before_replicate)
+ not event_filter.before_replicate(
+ diff.changes[:left].table,
+ helper.type_cast(diff.changes[:left].table, diff.changes[:left].key),
+ helper,
+ diff
+ )
+ else
+ false
+ end
+ end
+
# Executes the replication run.
def run
return unless [:left, :right].any? do |database|
changes_pending = false
t = Thread.new do
@@ -51,10 +68,12 @@
loaders.update # ensure the cache of change log records is up-to-date
diff = ReplicationDifference.new loaders
diff.load
break unless diff.loaded?
break if sweeper.terminated?
- replicator.replicate_difference diff if diff.type != :no_diff
+ if diff.type != :no_diff and not event_filtered?(diff)
+ replicator.replicate_difference diff
+ end
rescue Exception => e
begin
helper.log_replication_outcome diff, e.message,
e.class.to_s + "\n" + e.backtrace.join("\n")
rescue Exception => _