Class: Flipper::Adapters::Failover
- Inherits:
-
Object
- Object
- Flipper::Adapters::Failover
show all
- Includes:
- Flipper::Adapter
- Defined in:
- lib/flipper/adapters/failover.rb
Instance Method Summary
collapse
#default_config, #export, #import, included, #name, #read_only?
Constructor Details
#initialize(primary, secondary, options = {}) ⇒ Failover
Public: Build a new failover instance.
primary - The primary flipper adapter. secondary - The secondary flipper adapter which services reads when
the primary adapter is unavailable.
options - Hash of options:
:dual_write - Boolean, whether to update secondary when
primary is updated
:errors - Array of exception types for which to failover
16
17
18
19
20
21
22
|
# File 'lib/flipper/adapters/failover.rb', line 16
def initialize(primary, secondary, options = {})
@primary = primary
@secondary = secondary
@dual_write = options.fetch(:dual_write, false)
@errors = options.fetch(:errors, [ StandardError ])
end
|
Instance Method Details
#add(feature) ⇒ Object
48
49
50
51
52
|
# File 'lib/flipper/adapters/failover.rb', line 48
def add(feature)
@primary.add(feature).tap do
@secondary.add(feature) if @dual_write
end
end
|
#clear(feature) ⇒ Object
60
61
62
63
64
|
# File 'lib/flipper/adapters/failover.rb', line 60
def clear(feature)
@primary.clear(feature).tap do
@secondary.clear(feature) if @dual_write
end
end
|
#disable(feature, gate, thing) ⇒ Object
72
73
74
75
76
|
# File 'lib/flipper/adapters/failover.rb', line 72
def disable(feature, gate, thing)
@primary.disable(feature, gate, thing).tap do
@secondary.disable(feature, gate, thing) if @dual_write
end
end
|
#enable(feature, gate, thing) ⇒ Object
66
67
68
69
70
|
# File 'lib/flipper/adapters/failover.rb', line 66
def enable(feature, gate, thing)
@primary.enable(feature, gate, thing).tap do
@secondary.enable(feature, gate, thing) if @dual_write
end
end
|
#features ⇒ Object
24
25
26
27
28
|
# File 'lib/flipper/adapters/failover.rb', line 24
def features
@primary.features
rescue *@errors
@secondary.features
end
|
#get(feature) ⇒ Object
30
31
32
33
34
|
# File 'lib/flipper/adapters/failover.rb', line 30
def get(feature)
@primary.get(feature)
rescue *@errors
@secondary.get(feature)
end
|
#get_all ⇒ Object
42
43
44
45
46
|
# File 'lib/flipper/adapters/failover.rb', line 42
def get_all
@primary.get_all
rescue *@errors
@secondary.get_all
end
|
#get_multi(features) ⇒ Object
36
37
38
39
40
|
# File 'lib/flipper/adapters/failover.rb', line 36
def get_multi(features)
@primary.get_multi(features)
rescue *@errors
@secondary.get_multi(features)
end
|
#remove(feature) ⇒ Object
54
55
56
57
58
|
# File 'lib/flipper/adapters/failover.rb', line 54
def remove(feature)
@primary.remove(feature).tap do
@secondary.remove(feature) if @dual_write
end
end
|