From fa461dc8379e019cfae14913e0893e10079abeeb Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 7 Dec 2018 16:47:19 -0800 Subject: [PATCH] Check for existing CANCEL request, and exit on FINISHED If another CANCEL request has already been made just exit from uuid_cancel. If the build is FINISHED before it times out just exit, don't remove the finished results. Related: rhbz#1656691 --- src/pylorax/api/queue.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pylorax/api/queue.py b/src/pylorax/api/queue.py index 2236d423..b341799e 100644 --- a/src/pylorax/api/queue.py +++ b/src/pylorax/api/queue.py @@ -428,6 +428,11 @@ def uuid_cancel(cfg, uuid): Only call this if the build status is WAITING or RUNNING """ + cancel_path = joinpaths(cfg.get("composer", "lib_dir"), "results", uuid, "CANCEL") + if os.path.exists(cancel_path): + log.info("Cancel has already been requested for %s", uuid) + return False + # This status can change (and probably will) while it is in the middle of doing this: # It can move from WAITING -> RUNNING or it can move from RUNNING -> FINISHED|FAILED @@ -447,15 +452,16 @@ def uuid_cancel(cfg, uuid): return uuid_delete(cfg, uuid) # Tell the build to stop running - cancel_path = joinpaths(cfg.get("composer", "lib_dir"), "results", uuid, "CANCEL") open(cancel_path, "w").write("\n") - # Wait for status to move to FAILED + # Wait for status to move to FAILED or FINISHED started = time.time() while True: status = uuid_status(cfg, uuid) if status is None or status["queue_status"] == "FAILED": break + elif status is not None and status["queue_status"] == "FINISHED": + return False # Is this taking too long? Exit anyway and try to cleanup. if time.time() > started + (10 * 60):