diff --git a/src/pylorax/api/compose.py b/src/pylorax/api/compose.py index 321a8b55..5a59491b 100644 --- a/src/pylorax/api/compose.py +++ b/src/pylorax/api/compose.py @@ -49,7 +49,7 @@ from pykickstart.version import makeVersion from pylorax.api.projects import projects_depsolve, projects_depsolve_with_size, dep_nevra from pylorax.api.projects import ProjectsError from pylorax.api.recipes import read_recipe_and_id -from pylorax.api.timestamp import write_timestamp +from pylorax.api.timestamp import TS_CREATED, write_timestamp from pylorax.imgutils import default_image_name from pylorax.sysutils import joinpaths @@ -379,7 +379,7 @@ def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_m if test_mode > 0: open(joinpaths(results_dir, "TEST"), "w").write("%s" % test_mode) - write_timestamp(results_dir, "created") + write_timestamp(results_dir, TS_CREATED) log.info("Adding %s (%s %s) to compose queue", build_id, recipe["name"], compose_type) os.symlink(results_dir, joinpaths(lib_dir, "queue/new/", build_id)) diff --git a/src/pylorax/api/queue.py b/src/pylorax/api/queue.py index 78d49652..dc2d419d 100644 --- a/src/pylorax/api/queue.py +++ b/src/pylorax/api/queue.py @@ -31,7 +31,7 @@ import time from pylorax import find_templates from pylorax.api.compose import move_compose_results from pylorax.api.recipes import recipe_from_file -from pylorax.api.timestamp import write_timestamp, timestamp_dict +from pylorax.api.timestamp import TS_CREATED, TS_STARTED, TS_FINISHED, write_timestamp, timestamp_dict from pylorax.base import DataHolder from pylorax.creator import run_creator from pylorax.sysutils import joinpaths @@ -108,7 +108,7 @@ def monitor(cfg): make_compose(cfg, os.path.realpath(dst)) log.info("Finished building %s, results are in %s", dst, os.path.realpath(dst)) open(joinpaths(dst, "STATUS"), "w").write("FINISHED\n") - write_timestamp(dst, "finished") + write_timestamp(dst, TS_FINISHED) except Exception: import traceback log.error("traceback: %s", traceback.format_exc()) @@ -116,7 +116,7 @@ def monitor(cfg): # TODO - Write the error message to an ERROR-LOG file to include with the status # log.error("Error running compose: %s", e) open(joinpaths(dst, "STATUS"), "w").write("FAILED\n") - write_timestamp(dst, "finished") + write_timestamp(dst, TS_FINISHED) os.unlink(dst) @@ -197,7 +197,7 @@ def make_compose(cfg, results_dir): log.debug("cfg = %s", install_cfg) try: test_path = joinpaths(results_dir, "TEST") - write_timestamp(results_dir, "started") + write_timestamp(results_dir, TS_STARTED) if os.path.exists(test_path): # Pretend to run the compose time.sleep(5) @@ -286,9 +286,9 @@ def compose_detail(results_dir): return {"id": build_id, "queue_status": status, - "job_created": times.get("created"), - "job_started": times.get("started"), - "job_finished": times.get("finished"), + "job_created": times.get(TS_CREATED), + "job_started": times.get(TS_STARTED), + "job_finished": times.get(TS_FINISHED), "compose_type": compose_type, "blueprint": blueprint["name"], "version": blueprint["version"], diff --git a/src/pylorax/api/timestamp.py b/src/pylorax/api/timestamp.py index a0e3994d..9135ad4d 100644 --- a/src/pylorax/api/timestamp.py +++ b/src/pylorax/api/timestamp.py @@ -20,6 +20,10 @@ import time from pylorax.sysutils import joinpaths +TS_CREATED = "created" +TS_STARTED = "started" +TS_FINISHED = "finished" + def write_timestamp(destdir, ty): path = joinpaths(destdir, "times.toml") @@ -28,12 +32,12 @@ def write_timestamp(destdir, ty): except IOError: contents = toml.loads("") - if ty == "created": - contents["created"] = time.time() - elif ty == "started": - contents["started"] = time.time() - elif ty == "finished": - contents["finished"] = time.time() + if ty == TS_CREATED: + contents[TS_CREATED] = time.time() + elif ty == TS_STARTED: + contents[TS_STARTED] = time.time() + elif ty == TS_FINISHED: + contents[TS_FINISHED] = time.time() with open(path, "w") as f: f.write(toml.dumps(contents).encode("UTF-8"))