Class: Pinot::CircuitBreakerRegistry
- Inherits:
-
Object
- Object
- Pinot::CircuitBreakerRegistry
- Defined in:
- lib/pinot/circuit_breaker.rb
Overview
Registry of per-broker CircuitBreakers, shared across transport calls.
Instance Method Summary collapse
- #for(broker_address) ⇒ Object
-
#initialize(failure_threshold: 5, open_timeout: 30) ⇒ CircuitBreakerRegistry
constructor
A new instance of CircuitBreakerRegistry.
- #open?(broker_address) ⇒ Boolean
-
#reset_all ⇒ Object
Remove all state (useful for testing).
Constructor Details
#initialize(failure_threshold: 5, open_timeout: 30) ⇒ CircuitBreakerRegistry
Returns a new instance of CircuitBreakerRegistry.
90 91 92 93 94 95 |
# File 'lib/pinot/circuit_breaker.rb', line 90 def initialize(failure_threshold: 5, open_timeout: 30) @failure_threshold = failure_threshold @open_timeout = open_timeout @breakers = {} @mutex = Mutex.new end |
Instance Method Details
#for(broker_address) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/pinot/circuit_breaker.rb', line 97 def for(broker_address) @mutex.synchronize do @breakers[broker_address] ||= CircuitBreaker.new( failure_threshold: @failure_threshold, open_timeout: @open_timeout ) end end |
#open?(broker_address) ⇒ Boolean
106 107 108 |
# File 'lib/pinot/circuit_breaker.rb', line 106 def open?(broker_address) @mutex.synchronize { @breakers[broker_address]&.open? || false } end |
#reset_all ⇒ Object
Remove all state (useful for testing).
111 112 113 |
# File 'lib/pinot/circuit_breaker.rb', line 111 def reset_all @mutex.synchronize { @breakers.clear } end |