Class: CircuitBreakage::RedisBackedBreaker

Inherits:
Breaker
  • Object
show all
Defined in:
lib/circuit_breakage/redis_backed_breaker.rb

Overview

Similar to Breaker, but accepts a Redis connection and an arbitrary key, and will share state among an arbitrary number of RedisBackedBreakers via Redis. Relies on the SETNX redis command.

Constant Summary collapse

DEFAULT_LOCK_TIMEOUT =

How long before we decide a lock-holder has crashed, in seconds.

DEFAULT_TIMEOUT + 10

Constants inherited from Breaker

Breaker::DEFAULT_DURATION, Breaker::DEFAULT_FAILURE_THRESHOLD, Breaker::DEFAULT_TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Breaker

#block, #duration, #failure_count, #failure_threshold, #last_failed, #state, #timeout

Instance Method Summary collapse

Methods inherited from Breaker

#call

Constructor Details

#initialize(connection, key, block) ⇒ RedisBackedBreaker

Returns a new instance of RedisBackedBreaker.



13
14
15
16
17
18
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 13

def initialize(connection, key, block)
  @connection = connection
  @key = key
  @lock_timeout = DEFAULT_LOCK_TIMEOUT
  super(block)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 11

def connection
  @connection
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 11

def key
  @key
end

#lock_timeoutObject (readonly)

Returns the value of attribute lock_timeout.



11
12
13
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 11

def lock_timeout
  @lock_timeout
end