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:
commit
a83c5eca4b
1 changed files with 11 additions and 10 deletions
|
@ -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
|
|
||||||
retries -= 1
|
|
||||||
sleep(1)
|
|
||||||
elsif retries == 0
|
|
||||||
raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.")
|
|
||||||
end
|
|
||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue