Resend message while waiting for ostree ref

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ář <lsedlar@redhat.com>
Fixes: https://pagure.io/pungi/issue/1350
JIRA: COMPOSE-4166
This commit is contained in:
Lubomír Sedlář 2020-03-04 14:25:02 +01:00
parent 4734f9859a
commit 16d6e5b0dd
1 changed files with 17 additions and 16 deletions

View File

@ -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!")