Class: Fractor::Workflow::CircuitBreakerRegistry
- Inherits:
-
Object
- Object
- Fractor::Workflow::CircuitBreakerRegistry
- Defined in:
- lib/fractor/workflow/circuit_breaker_registry.rb
Overview
Registry for managing circuit breakers across jobs
Provides centralized circuit breaker management, allowing multiple jobs to share circuit breakers or have isolated ones.
Instance Method Summary collapse
-
#all_stats ⇒ Hash
Get statistics for all circuit breakers and orchestrators.
-
#clear ⇒ Object
Clear all circuit breakers and orchestrators.
-
#get(key) ⇒ CircuitBreaker?
Get an existing circuit breaker.
-
#get_or_create(key, **options) ⇒ CircuitBreaker
Get or create a circuit breaker.
-
#get_or_create_orchestrator(key, **options) ⇒ CircuitBreakerOrchestrator
Get or create a circuit breaker orchestrator.
-
#get_orchestrator(key) ⇒ CircuitBreakerOrchestrator?
Get an existing circuit breaker orchestrator.
-
#initialize ⇒ CircuitBreakerRegistry
constructor
A new instance of CircuitBreakerRegistry.
-
#remove(key) ⇒ CircuitBreaker, ...
Remove a circuit breaker.
-
#reset_all ⇒ Object
Reset all circuit breakers and orchestrators.
Constructor Details
#initialize ⇒ CircuitBreakerRegistry
Returns a new instance of CircuitBreakerRegistry.
24 25 26 27 28 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 24 def initialize @breakers = {} @orchestrators = {} @mutex = Mutex.new end |
Instance Method Details
#all_stats ⇒ Hash
Get statistics for all circuit breakers and orchestrators
97 98 99 100 101 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 97 def all_stats breakers_stats = @breakers.transform_values(&:stats) orchestrators_stats = @orchestrators.transform_values(&:stats) breakers_stats.merge(orchestrators_stats) end |
#clear ⇒ Object
Clear all circuit breakers and orchestrators
104 105 106 107 108 109 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 104 def clear @mutex.synchronize do @breakers.clear @orchestrators.clear end end |
#get(key) ⇒ CircuitBreaker?
Get an existing circuit breaker
64 65 66 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 64 def get(key) @breakers[key] end |
#get_or_create(key, **options) ⇒ CircuitBreaker
Get or create a circuit breaker
38 39 40 41 42 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 38 def get_or_create(key, **) @mutex.synchronize do @breakers[key] ||= CircuitBreaker.new(**) end end |
#get_or_create_orchestrator(key, **options) ⇒ CircuitBreakerOrchestrator
Get or create a circuit breaker orchestrator
54 55 56 57 58 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 54 def get_or_create_orchestrator(key, **) @mutex.synchronize do @orchestrators[key] ||= CircuitBreakerOrchestrator.new(**) end end |
#get_orchestrator(key) ⇒ CircuitBreakerOrchestrator?
Get an existing circuit breaker orchestrator
72 73 74 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 72 def get_orchestrator(key) @orchestrators[key] end |
#remove(key) ⇒ CircuitBreaker, ...
Remove a circuit breaker
80 81 82 83 84 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 80 def remove(key) @mutex.synchronize do @breakers.delete(key) || @orchestrators.delete(key) end end |
#reset_all ⇒ Object
Reset all circuit breakers and orchestrators
87 88 89 90 91 92 |
# File 'lib/fractor/workflow/circuit_breaker_registry.rb', line 87 def reset_all @mutex.synchronize do @breakers.each_value(&:reset) @orchestrators.each_value(&:reset!) end end |