class Flipper::Adapters::Sync::Synchronizer
Internal: Given a local and remote adapter, it can update the local to match the remote doing only the necessary enable/disable operations.
Public Class Methods
new(local, remote, options = {})
click to toggle source
# File lib/flipper/adapters/sync/synchronizer.rb, line 12 def initialize(local, remote, options = {}) @local = local @remote = remote @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop) end
Public Instance Methods
call()
click to toggle source
# File lib/flipper/adapters/sync/synchronizer.rb, line 18 def call @instrumenter.instrument("synchronizer_call.flipper") { sync } end
Private Instance Methods
sync()
click to toggle source
# File lib/flipper/adapters/sync/synchronizer.rb, line 24 def sync local_get_all = @local.get_all # TODO: Move remote get all to background thread to minimize impact to # whatever is happening in main thread. remote_get_all = @remote.get_all # Sync all the gate values. remote_get_all.each do |feature_key, remote_gates_hash| feature = Feature.new(feature_key, @local) local_gates_hash = local_get_all[feature_key] || @local.default_config local_gate_values = GateValues.new(local_gates_hash) remote_gate_values = GateValues.new(remote_gates_hash) FeatureSynchronizer.new(feature, local_gate_values, remote_gate_values).call end # Add features that are missing features_to_add = remote_get_all.keys - local_get_all.keys features_to_add.each { |key| Feature.new(key, @local).add } rescue => exception @instrumenter.instrument("synchronizer_exception.flipper", exception: exception) end