Class: RateThrottleClient::ExponentialBackoff
- Defined in:
- lib/rate_throttle_client/clients/exponential_backoff.rb
Overview
Actual exponential backoff class with some extra jazz so it reports when sleep goes back to zero
Essentially it doesn’t throttle at all until it hits a 429 then it exponentially throttles every repeatedly limited request. When it hits a successful request it stops rate throttling again.
Instance Attribute Summary
Attributes inherited from Base
#log, #min_sleep, #multiplier, #sleep_for
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from RateThrottleClient::Base
Instance Method Details
#call(&block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rate_throttle_client/clients/exponential_backoff.rb', line 9 def call(&block) sleep_for = @min_sleep while (req = yield) && req.status == 429 @log.call(Info.new(sleep_for: sleep_for, request: req)) sleep(sleep_for + jitter(sleep_for)) sleep_for *= @multiplier end # This no-op is needed to record that we've come out of a # retry state for the Demo class. sleep(0) req end |