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, #read_only?

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

#localObject (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 local
  @local
end

#remoteObject (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 remote
  @remote
end

#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

#adapter_stackObject



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

def adapter_stack
  "#{name}(local: #{@local.adapter_stack}, remote: #{@remote.adapter_stack})"
end

#add(feature) ⇒ Object



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

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

#clear(feature) ⇒ Object



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

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

#disable(feature, gate, thing) ⇒ Object



78
79
80
81
82
# File 'lib/flipper/adapters/sync.rb', line 78

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

#enable(feature, gate, thing) ⇒ Object



72
73
74
75
76
# File 'lib/flipper/adapters/sync.rb', line 72

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

#featuresObject



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

def features
  synchronize
  @local.features
end

#get(feature) ⇒ Object



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

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

#get_all(**kwargs) ⇒ Object



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

def get_all(**kwargs)
  synchronize
  @local.get_all(**kwargs)
end

#get_multi(features) ⇒ Object



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

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

#remove(feature) ⇒ Object



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

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