Class: SharedBroker::CircuitBreaker
- Inherits:
-
Object
- Object
- SharedBroker::CircuitBreaker
- Defined in:
- lib/shared_broker/circuit_breaker.rb
Defined Under Namespace
Classes: OpenError
Instance Attribute Summary collapse
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#failure_threshold ⇒ Object
readonly
Returns the value of attribute failure_threshold.
-
#recovery_timeout ⇒ Object
readonly
Returns the value of attribute recovery_timeout.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(failure_threshold: 5, recovery_timeout: 30) ⇒ CircuitBreaker
constructor
A new instance of CircuitBreaker.
- #run ⇒ Object
Constructor Details
#initialize(failure_threshold: 5, recovery_timeout: 30) ⇒ CircuitBreaker
Returns a new instance of CircuitBreaker.
11 12 13 14 15 16 17 18 |
# File 'lib/shared_broker/circuit_breaker.rb', line 11 def initialize(failure_threshold: 5, recovery_timeout: 30) @failure_threshold = failure_threshold @recovery_timeout = recovery_timeout @state = :closed @failure_count = 0 @last_failure_time = nil @mutex = Mutex.new end |
Instance Attribute Details
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
9 10 11 |
# File 'lib/shared_broker/circuit_breaker.rb', line 9 def failure_count @failure_count end |
#failure_threshold ⇒ Object (readonly)
Returns the value of attribute failure_threshold.
9 10 11 |
# File 'lib/shared_broker/circuit_breaker.rb', line 9 def failure_threshold @failure_threshold end |
#recovery_timeout ⇒ Object (readonly)
Returns the value of attribute recovery_timeout.
9 10 11 |
# File 'lib/shared_broker/circuit_breaker.rb', line 9 def recovery_timeout @recovery_timeout end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/shared_broker/circuit_breaker.rb', line 9 def state @state end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shared_broker/circuit_breaker.rb', line 20 def run check_state! begin result = yield success! result rescue => e record_failure! raise e end end |