lib/retriable.rb in retriable-2.0.2 vs lib/retriable.rb in retriable-2.1.0
- old
+ new
@@ -1,9 +1,9 @@
require "timeout"
-require "retriable/config"
-require "retriable/exponential_backoff"
-require "retriable/version"
+require_relative "retriable/config"
+require_relative "retriable/exponential_backoff"
+require_relative "retriable/version"
module Retriable
extend self
attr_reader :config
@@ -30,24 +30,25 @@
start_time = Time.now
elapsed_time = -> { Time.now - start_time }
if intervals
- tries = intervals.size
+ tries = intervals.size + 1
else
intervals = ExponentialBackoff.new(
- tries: tries,
+ tries: tries - 1,
base_interval: base_interval,
multiplier: multiplier,
max_interval: max_interval,
rand_factor: rand_factor
).intervals
end
exception_list = on.kind_of?(Hash) ? on.keys : on
- intervals.each.with_index(1) do |interval, try|
+ tries.times do |index|
+ try = index + 1
begin
if timeout
Timeout::timeout(timeout) { return yield(try) }
else
return yield(try)
@@ -63,9 +64,10 @@
end
end
raise unless message_match
end
+ interval = intervals[index]
on_retry.call(exception, try, elapsed_time.call, interval) if on_retry
raise if try >= tries || (elapsed_time.call + interval) > max_elapsed_time
sleep interval if config.sleep_disabled != true
end
end