Module: Semian::CircuitBreakerBehaviour
- Included in:
- AdaptiveCircuitBreaker, CircuitBreaker, DualCircuitBreaker
- Defined in:
- lib/semian/circuit_breaker_behaviour.rb
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#acquire(resource = nil, scope: nil, adapter: nil, &block) ⇒ Object
Main method to execute a block with circuit breaker protection.
-
#closed? ⇒ Boolean
Check if the circuit is closed (allowing requests).
-
#destroy ⇒ Object
Clean up resources.
-
#half_open? ⇒ Boolean
Check if the circuit is half-open (testing if service recovered).
-
#in_use? ⇒ Boolean
Check if the circuit breaker is actively tracking failures.
-
#initialize_behaviour(name:) ⇒ Object
Initialize common circuit breaker attributes.
-
#mark_failed(error, scope: nil, adapter: nil) ⇒ Object
Mark a request as failed.
-
#mark_success(scope: nil, adapter: nil) ⇒ Object
Mark a request as successful.
-
#open? ⇒ Boolean
Check if the circuit is open (rejecting requests).
-
#request_allowed? ⇒ Boolean
Check if requests are currently allowed.
-
#reset(scope: nil, adapter: nil) ⇒ Object
Reset the circuit breaker to its initial state.
Instance Attribute Details
#exceptions ⇒ Object
Returns the value of attribute exceptions.
6 7 8 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 6 def exceptions @exceptions end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
5 6 7 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 5 def last_error @last_error end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 5 def name @name end |
Instance Method Details
#acquire(resource = nil, scope: nil, adapter: nil, &block) ⇒ Object
Main method to execute a block with circuit breaker protection
15 16 17 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 15 def acquire(resource = nil, scope: nil, adapter: nil, &block) raise NotImplementedError, "#{self.class} must implement #acquire" end |
#closed? ⇒ Boolean
Check if the circuit is closed (allowing requests)
35 36 37 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 35 def closed? raise NotImplementedError, "#{self.class} must implement #closed?" end |
#destroy ⇒ Object
Clean up resources
25 26 27 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 25 def destroy raise NotImplementedError, "#{self.class} must implement #destroy" end |
#half_open? ⇒ Boolean
Check if the circuit is half-open (testing if service recovered)
40 41 42 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 40 def half_open? raise NotImplementedError, "#{self.class} must implement #half_open?" end |
#in_use? ⇒ Boolean
Check if the circuit breaker is actively tracking failures
60 61 62 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 60 def in_use? raise NotImplementedError, "#{self.class} must implement #in_use?" end |
#initialize_behaviour(name:) ⇒ Object
Initialize common circuit breaker attributes
9 10 11 12 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 9 def initialize_behaviour(name:) @name = name.to_sym @last_error = nil end |
#mark_failed(error, scope: nil, adapter: nil) ⇒ Object
Mark a request as failed
50 51 52 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 50 def mark_failed(error, scope: nil, adapter: nil) raise NotImplementedError, "#{self.class} must implement #mark_failed" end |
#mark_success(scope: nil, adapter: nil) ⇒ Object
Mark a request as successful
55 56 57 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 55 def mark_success(scope: nil, adapter: nil) raise NotImplementedError, "#{self.class} must implement #mark_success" end |
#open? ⇒ Boolean
Check if the circuit is open (rejecting requests)
30 31 32 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 30 def open? raise NotImplementedError, "#{self.class} must implement #open?" end |
#request_allowed? ⇒ Boolean
Check if requests are currently allowed
45 46 47 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 45 def request_allowed? raise NotImplementedError, "#{self.class} must implement #request_allowed?" end |
#reset(scope: nil, adapter: nil) ⇒ Object
Reset the circuit breaker to its initial state
20 21 22 |
# File 'lib/semian/circuit_breaker_behaviour.rb', line 20 def reset(scope: nil, adapter: nil) raise NotImplementedError, "#{self.class} must implement #reset" end |