util: Refactor retry function
When running a Bodhi update, somehow the raise condition was triggered before any exception was raised, which caused the compose to fail. This shouldn't really happen often, but it's possible if the machine adjusts time for any reason (e.g. DST). This commit moves the check for timeout after the function is called. This can cause an extra invocation of the function, which shouldn't be a huge deal really. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
160fc4f7df
commit
e12331db78
@ -972,11 +972,11 @@ def retry(timeout=120, interval=30, wait_on=Exception):
|
|||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while True:
|
while True:
|
||||||
if (time.time() - start) >= timeout:
|
|
||||||
raise # This re-raises the last exception.
|
|
||||||
try:
|
try:
|
||||||
return function(*args, **kwargs)
|
return function(*args, **kwargs)
|
||||||
except wait_on:
|
except wait_on:
|
||||||
|
if (time.time() - start) >= timeout:
|
||||||
|
raise # This re-raises the last exception.
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
Loading…
Reference in New Issue
Block a user