1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #2474 from anl/gce-exponential-backoff

[google|compute] Add exponential backoff to Google Compute Engine's backoff_if_unfound.
This commit is contained in:
Nat Welch 2013-12-11 23:33:34 -08:00
commit c5e6e2ae86

View file

@ -99,12 +99,14 @@ module Fog
def backoff_if_unfound(&block) def backoff_if_unfound(&block)
retries_remaining = 10 retries_remaining = 10
sleep_time = 0.1
begin begin
result = block.call result = block.call
rescue Exception => msg rescue Exception => msg
if msg.to_s.include? 'was not found' and retries_remaining > 0 if msg.to_s.include? 'was not found' and retries_remaining > 0
retries_remaining -= 1 retries_remaining -= 1
sleep 0.1 sleep sleep_time
sleep_time *= 1.6
retry retry
else else
raise msg raise msg