Class: Flipper::Adapters::Sync

Inherits:
Object
  • Object
show all
Includes:
Flipper::Adapter
Defined in:
lib/flipper/adapters/sync.rb,
lib/flipper/adapters/sync/synchronizer.rb,
lib/flipper/adapters/sync/feature_synchronizer.rb,
lib/flipper/adapters/sync/interval_synchronizer.rb

Overview

TODO: Syncing should happen in a background thread on a regular interval rather than in the main thread only when reads happen.

Defined Under Namespace

Classes: FeatureSynchronizer, IntervalSynchronizer, Synchronizer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Flipper::Adapter

#default_config, #export, #import, included, #name

Constructor Details

#initialize(local, remote, options = {}) ⇒ Sync

Public: Build a new sync instance.

local - The local flipper adapter that should serve reads. remote - The remote flipper adapter that should serve writes and update

the local on an interval.

interval - The Float or Integer number of seconds between syncs from remote to local. Default value is set in IntervalSynchronizer.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flipper/adapters/sync.rb', line 21

def initialize(local, remote, options = {})
  @local = local
  @remote = remote
  @synchronizer = options.fetch(:synchronizer) do
    sync_options = {
      raise: false,
    }
    instrumenter = options[:instrumenter]
    sync_options[:instrumenter] = instrumenter if instrumenter
    synchronizer = Synchronizer.new(@local, @remote, sync_options)
    IntervalSynchronizer.new(synchronizer, interval: options[:interval])
  end
  synchronize
end

Instance Attribute Details

#synchronizerObject (readonly)

Public: The synchronizer that will keep the local and remote in sync.



12
13
14
# File 'lib/flipper/adapters/sync.rb', line 12

def synchronizer
  @synchronizer
end

Instance Method Details

#add(feature) ⇒ Object



56
57
58
# File 'lib/flipper/adapters/sync.rb', line 56

def add(feature)
  @remote.add(feature).tap { @local.add(feature) }
end

#clear(feature) ⇒ Object



64
65
66
# File 'lib/flipper/adapters/sync.rb', line 64

def clear(feature)
  @remote.clear(feature).tap { @local.clear(feature) }
end

#disable(feature, gate, thing) ⇒ Object



74
75
76
77
78
# File 'lib/flipper/adapters/sync.rb', line 74

def disable(feature, gate, thing)
  @remote.disable(feature, gate, thing).tap do
    @local.disable(feature, gate, thing)
  end
end

#enable(feature, gate, thing) ⇒ Object



68
69
70
71
72
# File 'lib/flipper/adapters/sync.rb', line 68

def enable(feature, gate, thing)
  @remote.enable(feature, gate, thing).tap do
    @local.enable(feature, gate, thing)
  end
end

#featuresObject



36
37
38
39
# File 'lib/flipper/adapters/sync.rb', line 36

def features
  synchronize
  @local.features
end

#get(feature) ⇒ Object



41
42
43
44
# File 'lib/flipper/adapters/sync.rb', line 41

def get(feature)
  synchronize
  @local.get(feature)
end

#get_allObject



51
52
53
54
# File 'lib/flipper/adapters/sync.rb', line 51

def get_all
  synchronize
  @local.get_all
end

#get_multi(features) ⇒ Object



46
47
48
49
# File 'lib/flipper/adapters/sync.rb', line 46

def get_multi(features)
  synchronize
  @local.get_multi(features)
end

#remove(feature) ⇒ Object



60
61
62
# File 'lib/flipper/adapters/sync.rb', line 60

def remove(feature)
  @remote.remove(feature).tap { @local.remove(feature) }
end