Class: RateThrottleClient::ExponentialIncreaseGradualDecrease
- Defined in:
- lib/rate_throttle_client/clients/exponential_increase_gradual_decrease.rb
Instance Attribute Summary collapse
-
#decrease ⇒ Object
Returns the value of attribute decrease.
Attributes inherited from Base
#log, #min_sleep, #multiplier, #sleep_for
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(*args, decrease: nil, **kargs) ⇒ ExponentialIncreaseGradualDecrease
constructor
A new instance of ExponentialIncreaseGradualDecrease.
Methods inherited from Base
Constructor Details
#initialize(*args, decrease: nil, **kargs) ⇒ ExponentialIncreaseGradualDecrease
Returns a new instance of ExponentialIncreaseGradualDecrease.
5 6 7 8 |
# File 'lib/rate_throttle_client/clients/exponential_increase_gradual_decrease.rb', line 5 def initialize(*args, decrease: nil, **kargs) super(*args, **kargs) @decrease = decrease || @min_sleep end |
Instance Attribute Details
#decrease ⇒ Object
Returns the value of attribute decrease.
3 4 5 |
# File 'lib/rate_throttle_client/clients/exponential_increase_gradual_decrease.rb', line 3 def decrease @decrease end |
Instance Method Details
#call(&block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rate_throttle_client/clients/exponential_increase_gradual_decrease.rb', line 10 def call(&block) sleep_for = @sleep_for sleep(sleep_for + jitter(sleep_for)) while (req = yield) && req.status == 429 sleep_for += @min_sleep @log.call(Info.new(sleep_for: sleep_for, request: req)) sleep(sleep_for + jitter(sleep_for)) sleep_for *= @multiplier end if sleep_for >= @decrease sleep_for -= @decrease else sleep_for = 0 end @sleep_for = sleep_for req end |