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

Merge pull request #1748 from maginatics/timeout2

Fog::Model#wait_for: eliminate inner retry loop
This commit is contained in:
Wesley Beary 2013-04-11 08:00:16 -07:00
commit a83c5eca4b

View file

@ -60,18 +60,19 @@ module Fog
end end
def wait_for(timeout=Fog.timeout, interval=1, &block) def wait_for(timeout=Fog.timeout, interval=1, &block)
reload reload_has_succeeded = false
retries = 3 duration = Fog.wait_for(timeout, interval) do # Note that duration = false if it times out
Fog.wait_for(timeout, interval) do
if reload if reload
retries = 3 reload_has_succeeded = true
elsif retries > 0 instance_eval(&block)
retries -= 1 else
sleep(1) false
elsif retries == 0
raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.")
end end
instance_eval(&block) end
if reload_has_succeeded
return duration # false if timeout; otherwise {:duration => elapsed time }
else
raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} not present.")
end end
end end