From e12331db78428de4c1054e20e7437594a8892b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 31 Aug 2020 16:08:17 +0200 Subject: [PATCH] util: Refactor retry function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pungi/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pungi/util.py b/pungi/util.py index 68b192be..1965c86a 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -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