diff options
Diffstat (limited to 'gn_libs/jobs/launcher.py')
-rw-r--r-- | gn_libs/jobs/launcher.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/gn_libs/jobs/launcher.py b/gn_libs/jobs/launcher.py index 10a24b1..0b45a34 100644 --- a/gn_libs/jobs/launcher.py +++ b/gn_libs/jobs/launcher.py @@ -18,23 +18,20 @@ def run_job(conn, job, outputs_directory: Path): jobs.update_metadata(conn, job_id, "stdout-file", str(stdout_file)) jobs.update_metadata(conn, job_id, "stderr-file", str(stderr_file)) try: - with (# TODO: Add the output streams' files to job metadata - stdout_file.open(mode="w") as outfile, - stderr_file.open(mode="w") as errfile, - subprocess.Popen( - shlex.split(job["command"]), - encoding="utf-8", - stdout=outfile, - stderr=errfile) as process): - with (stdout_file.open(mode="r") as stdout_output, - stderr_file.open(mode="r") as stderr_output): - while process.poll() is None: - jobs.update_metadata(conn, job_id, "status", "running") - jobs.push_to_stream( - conn, job_id, "stdout", stdout_output.read()) - jobs.push_to_stream( - conn, job_id, "stderr", stderr_output.read()) - time.sleep(1) + with (stdout_file.open(mode="w") as outfile, + stderr_file.open(mode="w") as errfile, + stdout_file.open(mode="r") as stdout_in, + stderr_file.open(mode="r") as stderr_in, + subprocess.Popen( + shlex.split(job["command"]), + encoding="utf-8", + stdout=outfile, + stderr=errfile) as process): + while process.poll() is None: + jobs.update_metadata(conn, job_id, "status", "running") + jobs.push_to_stream(conn, job_id, "stdout", stdout_in.read()) + jobs.push_to_stream(conn, job_id, "stderr", stderr_in.read()) + time.sleep(1) except: jobs.update_metadata(conn, job_id, "status", "error") jobs.push_to_stream(conn, job_id, "stderr", traceback.format_exc()) |