Module: Ferrum::Utils::Attempt
- Defined in:
- lib/ferrum/utils/attempt.rb
Overview
A retry-with-backoff helper for re-running a block a fixed number of times when it raises one of a given set of exceptions, sleeping between attempts.
Class Method Summary collapse
-
.with_retry(errors:, max:, wait:) ⇒ Object
Retries the block up to
maxtimes when one oferrorsis raised, sleepingwaitseconds between attempts.
Class Method Details
.with_retry(errors:, max:, wait:) ⇒ Object
Retries the block up to max times when one of errors is raised,
sleeping wait seconds between attempts.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ferrum/utils/attempt.rb', line 28 def with_retry(errors:, max:, wait:) attempts ||= 1 yield rescue *Array(errors) raise if attempts >= max attempts += 1 sleep(wait) retry end |