Module: Retryable
- Extended by:
- Decoratable
- Defined in:
- lib/decoratable/retryable.rb
Constant Summary collapse
- NO_BACKOFF =
proc { 0 }
- LINEAR_BACKOFF =
proc { |n| n + 1 }
- EXPONENTIAL_BACKOFF =
proc { |n| 2**n }
Instance Method Summary collapse
Methods included from Decoratable
Instance Method Details
#retryable(tries = 1, on: [RuntimeError], backoff: NO_BACKOFF) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/decoratable/retryable.rb', line 10 def retryable(tries = 1, on: [RuntimeError], backoff: NO_BACKOFF) attempts = 0 on = Array(on) begin yield rescue *on if attempts >= tries raise else sleep backoff.call(attempts) attempts += 1 retry end end end |