Class: SimpleCircuitBreaker
- Inherits:
-
Object
- Object
- SimpleCircuitBreaker
- Defined in:
- lib/simple_circuit_breaker.rb
Defined Under Namespace
Classes: CircuitOpenError
Constant Summary collapse
- VERSION =
'0.3.0'
Instance Attribute Summary collapse
-
#failure_threshold ⇒ Object
readonly
Returns the value of attribute failure_threshold.
-
#retry_timeout ⇒ Object
readonly
Returns the value of attribute retry_timeout.
Instance Method Summary collapse
- #handle(*exceptions, &block) ⇒ Object
-
#initialize(failure_threshold = 3, retry_timeout = 10) ⇒ SimpleCircuitBreaker
constructor
A new instance of SimpleCircuitBreaker.
Constructor Details
#initialize(failure_threshold = 3, retry_timeout = 10) ⇒ SimpleCircuitBreaker
Returns a new instance of SimpleCircuitBreaker.
9 10 11 12 13 |
# File 'lib/simple_circuit_breaker.rb', line 9 def initialize(failure_threshold=3, retry_timeout=10) @failure_threshold = failure_threshold @retry_timeout = retry_timeout reset! end |
Instance Attribute Details
#failure_threshold ⇒ Object (readonly)
Returns the value of attribute failure_threshold.
7 8 9 |
# File 'lib/simple_circuit_breaker.rb', line 7 def failure_threshold @failure_threshold end |
#retry_timeout ⇒ Object (readonly)
Returns the value of attribute retry_timeout.
7 8 9 |
# File 'lib/simple_circuit_breaker.rb', line 7 def retry_timeout @retry_timeout end |
Instance Method Details
#handle(*exceptions, &block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/simple_circuit_breaker.rb', line 15 def handle(*exceptions, &block) if tripped? raise CircuitOpenError, 'Circuit is open' else execute(exceptions, &block) end end |