Class: SwitchGear::CircuitBreaker::Redis
- Inherits:
-
Object
- Object
- SwitchGear::CircuitBreaker::Redis
- Includes:
- SwitchGear::CircuitBreaker
- Defined in:
- lib/switch_gear/circuit_breaker/redis.rb
Instance Attribute Summary collapse
-
#circuit ⇒ Object
(look to Memory#circuit).
-
#client ⇒ Object
An instance of an redis client.
-
#failure_limit ⇒ Object
(look to Memory#failure_limit).
-
#failures ⇒ Object
(look to Memory#failures).
-
#logger ⇒ Object
(look to Memory#logger).
-
#namespace ⇒ String
A unique name that will be used across servers to sync state and failures.
-
#reset_timeout ⇒ Object
(look to Memory#reset_timeout).
-
#state ⇒ Object
(look to Memory#state).
Instance Method Summary collapse
- #add_failure(failure) ⇒ Object
-
#initialize {|circuit, failure_limit, reset_timeout, logger, client, namespace| ... } ⇒ SwitchGear::CircuitBreaker::Redis
constructor
The main class to instantiate the CircuitBraker class.
Methods included from SwitchGear::CircuitBreaker
#call, #closed?, #failure_count, #half_open?, #open?
Constructor Details
#initialize {|circuit, failure_limit, reset_timeout, logger, client, namespace| ... } ⇒ SwitchGear::CircuitBreaker::Redis
The main class to instantiate the CircuitBraker class.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 49 def initialize yield self @client = client @namespace = namespace @failure_limit ||= 5 @reset_timeout ||= 10 @logger = Logger.new(STDOUT) run_validations @namespace = "circuit_breaker:#{namespace}" end |
Instance Attribute Details
#circuit ⇒ Object
(look to Memory#circuit)
6 7 8 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 6 def circuit @circuit end |
#client ⇒ Object
An instance of an redis client. This library does not have a hard dependency on a particular redis client but for testing I've used [redis-rb](github.com/redis/redis-rb). Whatever you pass in here simply has to implement a few redis commands such as `sadd`, `del`, `smembers`, `get` and `set`. The client will ensure these exist before the breaker can be instantiated.
29 30 31 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 29 def client @client end |
#failure_limit ⇒ Object
(look to Memory#failure_limit)
8 9 10 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 8 def failure_limit @failure_limit end |
#failures ⇒ Object
(look to Memory#failures)
16 17 18 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 16 def failures @failures end |
#logger ⇒ Object
(look to Memory#logger)
12 13 14 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 12 def logger @logger end |
#namespace ⇒ String
A unique name that will be used across servers to sync state and failures. I'd recommend `your_class.name:your_method_name` or whatever is special about what's being invoked in the `circuit`. See examples/example_redis.rb
21 22 23 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 21 def namespace @namespace end |
#reset_timeout ⇒ Object
(look to Memory#reset_timeout)
10 11 12 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 10 def reset_timeout @reset_timeout end |
#state ⇒ Object
(look to Memory#state)
14 15 16 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 14 def state @state end |
Instance Method Details
#add_failure(failure) ⇒ Object
79 80 81 |
# File 'lib/switch_gear/circuit_breaker/redis.rb', line 79 def add_failure(failure) client.sadd(fail_namespace, failure.to_json) end |