1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
module Flipper
module Adapters
class Failover
include ::Flipper::Adapter
# Public: The name of the adapter.
attr_reader :name
# 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
def initialize(primary, secondary, options = {})
@name = :failover
@primary = primary
@secondary = secondary
@dual_write = options.fetch(:dual_write, false)
@errors = options.fetch(:errors, [ StandardError ])
end
def features
@primary.features
rescue *@errors
@secondary.features
end
def get(feature)
@primary.get(feature)
rescue *@errors
@secondary.get(feature)
end
def get_multi(features)
@primary.get_multi(features)
rescue *@errors
@secondary.get_multi(features)
end
def get_all
@primary.get_all
rescue *@errors
@secondary.get_all
end
def add(feature)
@primary.add(feature).tap do
@secondary.add(feature) if @dual_write
end
end
def remove(feature)
@primary.remove(feature).tap do
@secondary.remove(feature) if @dual_write
end
end
def clear(feature)
@primary.clear(feature).tap do
@secondary.clear(feature) if @dual_write
end
end
def enable(feature, gate, thing)
@primary.enable(feature, gate, thing).tap do
@secondary.enable(feature, gate, thing) if @dual_write
end
end
def disable(feature, gate, thing)
@primary.disable(feature, gate, thing).tap do
@secondary.disable(feature, gate, thing) if @dual_write
end
end
end
end
end
|