Class: RateThrottleClient::ExponentialIncreaseProportionalDecrease
- Defined in:
- lib/rate_throttle_client/clients/exponential_increase_proportional_decrease.rb
Instance Attribute Summary collapse
-
#decrease_divisor ⇒ Object
Returns the value of attribute decrease_divisor.
Attributes inherited from Base
#log, #min_sleep, #multiplier, #sleep_for
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(*args, decrease_divisor: nil, **kargs) ⇒ ExponentialIncreaseProportionalDecrease
constructor
A new instance of ExponentialIncreaseProportionalDecrease.
Methods inherited from Base
Constructor Details
#initialize(*args, decrease_divisor: nil, **kargs) ⇒ ExponentialIncreaseProportionalDecrease
Returns a new instance of ExponentialIncreaseProportionalDecrease.
5 6 7 8 |
# File 'lib/rate_throttle_client/clients/exponential_increase_proportional_decrease.rb', line 5 def initialize(*args, decrease_divisor: nil, **kargs) super(*args, **kargs) @decrease_divisor = (decrease_divisor || RateThrottleClient.max_limit).to_f end |
Instance Attribute Details
#decrease_divisor ⇒ Object
Returns the value of attribute decrease_divisor.
3 4 5 |
# File 'lib/rate_throttle_client/clients/exponential_increase_proportional_decrease.rb', line 3 def decrease_divisor @decrease_divisor 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 33 34 |
# File 'lib/rate_throttle_client/clients/exponential_increase_proportional_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 decrease_value = sleep_for / @decrease_divisor if sleep_for >= decrease_value sleep_for -= decrease_value else sleep_for = 0 end @sleep_for = sleep_for req end |