Module: SwitchGear::CircuitBreaker
- Defined in:
- lib/switch_gear/circuit_breaker.rb,
lib/switch_gear/circuit_breaker/redis.rb,
lib/switch_gear/circuit_breaker/memory.rb,
lib/switch_gear/circuit_breaker/failure.rb,
lib/switch_gear/circuit_breaker/open_error.rb
Defined Under Namespace
Classes: Failure, Memory, OpenError, Redis
Instance Method Summary collapse
- #add_failure(failure) ⇒ void
-
#call(*args) ⇒ Void, SwitchGear::CircuitBreaker::Open
Calls the circuit proc/lambda if the circuit is closed or half-open.
-
#closed? ⇒ Boolean
Whether the circuit is closed.
-
#failure_count ⇒ Integer
The count of current failures.
-
#failures ⇒ Array<SwitchGear::CircuitBreaker::Failure>
A list of current failures.
- #failures=(failure) ⇒ void
-
#half_open? ⇒ Boolean
Whether the circuit is half-open.
-
#open? ⇒ Boolean
Whether the circuit is open.
-
#state ⇒ Symbol
-
either :open, :closed, :half-open.
-
- #state=(state) ⇒ void
Instance Method Details
#add_failure(failure) ⇒ void
This method returns an undefined value.
52 53 54 |
# File 'lib/switch_gear/circuit_breaker.rb', line 52 def add_failure(failure) must_implement(:add_failure) end |
#call(*args) ⇒ Void, SwitchGear::CircuitBreaker::Open
Calls the circuit proc/lambda if the circuit is closed or half-open.
13 14 15 16 17 |
# File 'lib/switch_gear/circuit_breaker.rb', line 13 def call(*args) check_reset_timeout raise OpenError if open? do_run(args, &circuit) end |
#closed? ⇒ Boolean
Returns Whether the circuit is closed
30 31 32 |
# File 'lib/switch_gear/circuit_breaker.rb', line 30 def closed? state == :closed end |
#failure_count ⇒ Integer
Returns The count of current failures
20 21 22 |
# File 'lib/switch_gear/circuit_breaker.rb', line 20 def failure_count failures.size end |
#failures ⇒ Array<SwitchGear::CircuitBreaker::Failure>
Returns a list of current failures
40 41 42 |
# File 'lib/switch_gear/circuit_breaker.rb', line 40 def failures must_implement(:failures) end |
#failures=(failure) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/switch_gear/circuit_breaker.rb', line 46 def failures=(failure) must_implement(:failures=) end |
#half_open? ⇒ Boolean
Returns Whether the circuit is half-open
35 36 37 |
# File 'lib/switch_gear/circuit_breaker.rb', line 35 def half_open? state == :half_open end |
#open? ⇒ Boolean
Returns Whether the circuit is open
25 26 27 |
# File 'lib/switch_gear/circuit_breaker.rb', line 25 def open? state == :open end |
#state ⇒ Symbol
Returns - either :open, :closed, :half-open
57 58 59 |
# File 'lib/switch_gear/circuit_breaker.rb', line 57 def state must_implement(:state) end |
#state=(state) ⇒ void
This method returns an undefined value.
63 64 65 |
# File 'lib/switch_gear/circuit_breaker.rb', line 63 def state=(state) must_implement(:state=) end |