Class: Attio::CompositeCircuitBreaker Private
- Inherits:
-
Object
- Object
- Attio::CompositeCircuitBreaker
- Defined in:
- lib/attio/circuit_breaker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Composite circuit breaker for multiple endpoints
Instance Method Summary collapse
-
#call(key) { ... } ⇒ Object
private
Execute with circuit breaker for endpoint.
-
#for_endpoint(key, config = {}) ⇒ CircuitBreaker
private
Get or create circuit breaker for endpoint.
-
#initialize(default_config = {}) ⇒ CompositeCircuitBreaker
constructor
private
A new instance of CompositeCircuitBreaker.
-
#reset_all! ⇒ Object
private
Reset all circuit breakers.
-
#states ⇒ Hash
private
Get all circuit breaker states.
-
#stats ⇒ Hash
private
Get aggregated statistics.
Constructor Details
#initialize(default_config = {}) ⇒ CompositeCircuitBreaker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CompositeCircuitBreaker.
245 246 247 248 249 250 251 252 253 |
# File 'lib/attio/circuit_breaker.rb', line 245 def initialize(default_config = {}) @breakers = {} @default_config = { threshold: 5, timeout: 60, half_open_requests: 3, }.merge(default_config) @mutex = Mutex.new end |
Instance Method Details
#call(key) { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute with circuit breaker for endpoint
270 271 272 |
# File 'lib/attio/circuit_breaker.rb', line 270 def call(key, &block) for_endpoint(key).call(&block) end |
#for_endpoint(key, config = {}) ⇒ CircuitBreaker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get or create circuit breaker for endpoint
260 261 262 263 264 |
# File 'lib/attio/circuit_breaker.rb', line 260 def for_endpoint(key, config = {}) @mutex.synchronize do @breakers[key] ||= CircuitBreaker.new(**@default_config, **config) end end |
#reset_all! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset all circuit breakers
293 294 295 296 297 |
# File 'lib/attio/circuit_breaker.rb', line 293 def reset_all! @mutex.synchronize do @breakers.each_value(&:reset!) end end |
#states ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get all circuit breaker states
277 278 279 280 281 |
# File 'lib/attio/circuit_breaker.rb', line 277 def states @mutex.synchronize do @breakers.transform_values(&:state) end end |
#stats ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get aggregated statistics
286 287 288 289 290 |
# File 'lib/attio/circuit_breaker.rb', line 286 def stats @mutex.synchronize do @breakers.transform_values(&:stats) end end |