Module: TypeformData::Utils
- Defined in:
- lib/typeform_data/utils.rb
Class Method Summary collapse
-
.retry_with_exponential_backoff(config, retry_exceptions, max_retries: 5, initial_wait: 1) ⇒ Object
Repeats the block until it succeeds or a limit is reached, waiting twice as long as it previously did after each failure.
Class Method Details
.retry_with_exponential_backoff(config, retry_exceptions, max_retries: 5, initial_wait: 1) ⇒ Object
Repeats the block until it succeeds or a limit is reached, waiting twice as long as it previously did after each failure.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/typeform_data/utils.rb', line 11 def self.retry_with_exponential_backoff(config, retry_exceptions, max_retries: 5, initial_wait: 1) seconds_to_wait = initial_wait max_retries.times do |iteration| begin break yield rescue *retry_exceptions config.logger.warn "Retry. Waiting #{seconds_to_wait}s, attempt #{iteration} of "\ "#{max_retries}." sleep seconds_to_wait seconds_to_wait *= 2 raise if iteration == max_retries - 1 end end end |