From 16d6e5b0ddb471643e6800e82b6ae8e7b44933be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 4 Mar 2020 14:25:02 +0100 Subject: [PATCH] Resend message while waiting for ostree ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the signing machinery crashes, we don't want to wait forever. This way at least we can shout for help periodically. Signed-off-by: Lubomír Sedlář Fixes: https://pagure.io/pungi/issue/1350 JIRA: COMPOSE-4166 --- .../scripts/wait_for_signed_ostree_handler.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pungi/scripts/wait_for_signed_ostree_handler.py b/pungi/scripts/wait_for_signed_ostree_handler.py index 9126337e..eaf594ff 100644 --- a/pungi/scripts/wait_for_signed_ostree_handler.py +++ b/pungi/scripts/wait_for_signed_ostree_handler.py @@ -21,6 +21,9 @@ import os import sys import time +RESEND_INTERVAL = 300 # In seconds +SLEEP_TIME = 5 + def is_ref_updated(ref_file, commit): """The ref is updated when the file points to the correct commit.""" @@ -66,21 +69,19 @@ def main(): fedmsg.init(**config) topic = "compose.%s" % opts.cmd.replace("-", ".").lower() - count = 0 - while not os.path.exists(path): - ts_log("Commit not signed yet, waiting...") - count += 1 - if count >= 60: # Repeat every 5 minutes - print("Repeating notification") - fedmsg.publish(topic=topic, modname="pungi", msg=data) - count = 0 - time.sleep(5) - - print("Found signature, waiting for ref to be updated.") + def wait_for(msg, test, *args): + time_slept = 0 + while not test(*args): + ts_log(msg) + time_slept += SLEEP_TIME + if time_slept >= RESEND_INTERVAL: + ts_log("Repeating notification") + fedmsg.publish(topic=topic, modname="pungi", msg=data) + time_slept = 0 + time.sleep(SLEEP_TIME) + wait_for("Commit not signed yet", os.path.exists, path) + ts_log("Found signature, waiting for ref to be updated.") ref_file = os.path.join(repo, "refs/heads", data["ref"]) - while not is_ref_updated(ref_file, commit): - ts_log("Ref is not yet up-to-date, waiting...") - time.sleep(5) - - print("Ref is up-to-date. All done!") + wait_for("Ref is not yet up-to-date", is_ref_updated, ref_file, commit) + ts_log("Ref is up-to-date. All done!")