Class: CircuitBreakage::RedisBackedBreaker
- 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_NEVER_TRIP_ON, Breaker::DEFAULT_ONLY_TRIP_ON, Breaker::DEFAULT_TIMEOUT
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#lock_timeout ⇒ Object
readonly
Returns the value of attribute lock_timeout.
Attributes inherited from Breaker
#block, #duration, #failure_threshold, #last_exception, #never_trip_on, #only_trip_on, #timeout
Instance Method Summary collapse
- #failure_count ⇒ Object
- #failure_count=(value) ⇒ Object
-
#initialize(connection, key, block) ⇒ RedisBackedBreaker
constructor
A new instance of RedisBackedBreaker.
- #last_failed ⇒ Object
- #last_failed=(value) ⇒ Object
- #state ⇒ Object
- #state=(value) ⇒ Object
Methods inherited from Breaker
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 11 def connection @connection end |
#key ⇒ Object (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_timeout ⇒ Object (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 |
Instance Method Details
#failure_count ⇒ Object
28 29 30 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 28 def failure_count @connection.get("#{@key}/attrs/failure_count").to_i end |
#failure_count=(value) ⇒ Object
32 33 34 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 32 def failure_count=(value) @connection.set("#{@key}/attrs/failure_count", value) end |
#last_failed ⇒ Object
36 37 38 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 36 def last_failed @connection.get("#{@key}/attrs/last_failed").to_i end |
#last_failed=(value) ⇒ Object
40 41 42 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 40 def last_failed=(value) @connection.set("#{@key}/attrs/last_failed", value) end |
#state ⇒ Object
20 21 22 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 20 def state @connection.get("#{@key}/attrs/state") end |
#state=(value) ⇒ Object
24 25 26 |
# File 'lib/circuit_breakage/redis_backed_breaker.rb', line 24 def state=(value) @connection.set("#{@key}/attrs/state", value) end |