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:
Lubomír Sedlář 2020-08-31 16:08:17 +02:00 committed by lsedlar
parent 160fc4f7df
commit e12331db78

View File

@ -972,11 +972,11 @@ def retry(timeout=120, interval=30, wait_on=Exception):
def inner(*args, **kwargs):
start = time.time()
while True:
if (time.time() - start) >= timeout:
raise # This re-raises the last exception.
try:
return function(*args, **kwargs)
except wait_on:
if (time.time() - start) >= timeout:
raise # This re-raises the last exception.
time.sleep(interval)
return inner