FinalCAD / retryable_block

Method to retry block if it returns errors.
MIT License
0 stars 1 forks source link

Exponential backoff #2

Open joel opened 6 years ago

joel commented 6 years ago

Add an algorithm used to space out repeated retries

thomas-riboulet-finalcad commented 6 years ago

good practices point out to using a growing delay between retries.

examples :

joel commented 6 years ago

awesome sample

def sleep_amount(retries)
  retry_index = @options.max - retries
  current_interval = @options.interval * (@options.backoff_factor ** retry_index)
  current_interval = [current_interval, @options.max_interval].min
  random_interval  = rand * @options.interval_randomness.to_f * @options.interval
  current_interval + random_interval
end