Class: Pinot::CircuitBreakerRegistry
- Inherits:
-
Object
- Object
- Pinot::CircuitBreakerRegistry
- Defined in:
- lib/pinot/circuit_breaker.rb
Overview
Thread-safe registry that lazily creates and caches one CircuitBreaker per broker address string. Shared by all Connection instances built from the same ClientConfig so that failures from parallel queries accumulate correctly.
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.
118 119 120 121 122 123 |
# File 'lib/pinot/circuit_breaker.rb', line 118 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
125 126 127 128 129 130 131 132 |
# File 'lib/pinot/circuit_breaker.rb', line 125 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
134 135 136 |
# File 'lib/pinot/circuit_breaker.rb', line 134 def open?(broker_address) @mutex.synchronize { @breakers[broker_address]&.open? || false } end |
#reset_all ⇒ Object
Remove all state (useful for testing).
139 140 141 |
# File 'lib/pinot/circuit_breaker.rb', line 139 def reset_all @mutex.synchronize { @breakers.clear } end |