From 0baa524d8dc0cd232a1a117714f173d38564aaae 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. (cherry picked from commit 962d10b3b74e99f95c6808bf95b35322319ebca9) Related: rhbz#1659129 --- 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 8da45c96..d3c711f9 100644 --- a/src/pylorax/api/queue.py +++ b/src/pylorax/api/queue.py @@ -424,6 +424,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 @@ -443,15 +448,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):