mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
adjustable max for eventually
This commit is contained in:
parent
97dda626ba
commit
cb6a1d85f8
1 changed files with 15 additions and 3 deletions
|
@ -48,14 +48,26 @@ def eu_s3
|
|||
end
|
||||
end
|
||||
|
||||
def eventually(&block)
|
||||
[0,2,4,8,16].each do |delay|
|
||||
def eventually(max_delay = 16, &block)
|
||||
delays = [0]
|
||||
delay_step = 1
|
||||
total = 0
|
||||
while true
|
||||
delay = 1
|
||||
delay_step.times do
|
||||
delay *= 2
|
||||
end
|
||||
delays << delay
|
||||
delay_step += 1
|
||||
break if delay >= max_delay
|
||||
end
|
||||
delays.each do |delay|
|
||||
begin
|
||||
sleep(delay)
|
||||
yield
|
||||
break
|
||||
rescue => error
|
||||
raise error if delay == 16
|
||||
raise error if delay >= max_delay
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue