Module: Cachext::Features::CircuitBreaker

Included in:
Client
Defined in:
lib/cachext/features/circuit_breaker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#breakerObject (readonly)

Returns the value of attribute breaker.



4
5
6
# File 'lib/cachext/features/circuit_breaker.rb', line 4

def breaker
  @breaker
end

Instance Method Details

#handle_error(key, options, error) ⇒ Object



23
24
25
26
# File 'lib/cachext/features/circuit_breaker.rb', line 23

def handle_error key, options, error
  breaker.for(key).increment_failure
  super
end

#initialize(config) ⇒ Object



6
7
8
9
# File 'lib/cachext/features/circuit_breaker.rb', line 6

def initialize config
  super
  @breaker = Breaker.new(config)
end

#read(key, options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cachext/features/circuit_breaker.rb', line 11

def read key, options
  circuit = breaker.for(key)
  if circuit.open?
    val = key.read_backup
    debug_log { { m: :circuit_open, key: key, msg: "Circuit breaker open, reading from backup", val: val.inspect } }
    val
  else
    circuit.check_health
    super
  end
end