Class: ThrottleMachines::HedgedBreaker
- Inherits:
-
Object
- Object
- ThrottleMachines::HedgedBreaker
- Defined in:
- lib/throttle_machines/hedged_breaker.rb
Overview
Hedged request with circuit breaker integration
Instance Method Summary collapse
-
#initialize(breakers, delay: 0.05) ⇒ HedgedBreaker
constructor
A new instance of HedgedBreaker.
- #run(&block) ⇒ Object
Constructor Details
#initialize(breakers, delay: 0.05) ⇒ HedgedBreaker
Returns a new instance of HedgedBreaker.
6 7 8 9 10 11 12 |
# File 'lib/throttle_machines/hedged_breaker.rb', line 6 def initialize(breakers, delay: 0.05) @breakers = Array(breakers) @hedged = HedgedRequest.new( delay: delay, max_attempts: @breakers.size ) end |
Instance Method Details
#run(&block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/throttle_machines/hedged_breaker.rb', line 14 def run(&block) @hedged.run do |attempt| breaker = @breakers[attempt] next if breaker.nil? breaker.call(&block) end end |