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, #import, included

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 adpater 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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flipper/adapters/sync.rb', line 25

def initialize(local, remote, options = {})
  @name = :sync
  @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
  sync
end

Instance Attribute Details

#nameObject (readonly)

Public: The name of the adapter.



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

def name
  @name
end

#synchronizerObject (readonly)

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



16
17
18
# File 'lib/flipper/adapters/sync.rb', line 16

def synchronizer
  @synchronizer
end

Instance Method Details

#add(feature) ⇒ Object



61
62
63
64
65
# File 'lib/flipper/adapters/sync.rb', line 61

def add(feature)
  result = @remote.add(feature)
  @local.add(feature)
  result
end

#clear(feature) ⇒ Object



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

def clear(feature)
  result = @remote.clear(feature)
  @local.clear(feature)
  result
end

#disable(feature, gate, thing) ⇒ Object



85
86
87
88
89
# File 'lib/flipper/adapters/sync.rb', line 85

def disable(feature, gate, thing)
  result = @remote.disable(feature, gate, thing)
  @local.disable(feature, gate, thing)
  result
end

#enable(feature, gate, thing) ⇒ Object



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

def enable(feature, gate, thing)
  result = @remote.enable(feature, gate, thing)
  @local.enable(feature, gate, thing)
  result
end

#featuresObject



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

def features
  sync
  @local.features
end

#get(feature) ⇒ Object



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

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

#get_allObject



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

def get_all
  sync
  @local.get_all
end

#get_multi(features) ⇒ Object



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

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

#remove(feature) ⇒ Object



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

def remove(feature)
  result = @remote.remove(feature)
  @local.remove(feature)
  result
end