diff options
| author | Alexander_Kabui | 2025-01-23 16:14:07 +0300 |
|---|---|---|
| committer | BonfaceKilz | 2025-02-06 12:43:15 +0300 |
| commit | ca0f0bdda646de1b3862daf82c5cfb6889547f5f (patch) | |
| tree | 7c50da2717329481094ef8f49e1a85678f5972e4 /gn3/computations/streaming.py | |
| parent | 6ac8307f7cb8e0d99b694b35ea3669f24715a0f2 (diff) | |
| download | genenetwork3-ca0f0bdda646de1b3862daf82c5cfb6889547f5f.tar.gz | |
refactor: Refactor run_process function.
Diffstat (limited to 'gn3/computations/streaming.py')
| -rw-r--r-- | gn3/computations/streaming.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gn3/computations/streaming.py b/gn3/computations/streaming.py index 78ce23b..2b0a4e4 100644 --- a/gn3/computations/streaming.py +++ b/gn3/computations/streaming.py @@ -5,12 +5,12 @@ from functools import wraps from flask import current_app, request -def run_process(cmd, output_file, run_id): +def run_process(cmd, log_file, run_id): """Function to execute an external process and capture the stdout in a file input: cmd: the command to execute as a list of args. - output_file: abs file path to write the stdout. + log_file: abs file path to write the stdout. run_id: unique id to identify the process output: @@ -25,16 +25,19 @@ def run_process(cmd, output_file, run_id): ) as process: for line in iter(process.stdout.readline, b""): # phase: capture the stdout for each line allowing read and write - with open(output_file, "a+", encoding="utf-8") as file_handler: + with open(log_file, "a+", encoding="utf-8") as file_handler: file_handler.write(line.decode("utf-8")) process.wait() - if process.returncode == 0: - return {"msg": "success", "code": 0, "run_id": run_id} - return {"msg": "error occurred", "error": "Process failed", - "code": process.returncode, "run_id": run_id} + return {"msg": "success" if process.returncode == 0 else "Process failed", + "run_id": run_id, + "log_file": log_file, + "code": process.returncode} except subprocess.CalledProcessError as error: - return {"msg": "error occurred", "code":error.returncode, - "error": str(error), "run_id": run_id} + return {"msg": "error occurred", + "code": error.returncode, + "error": str(error), + "run_id": run_id, + "log_file": log_file} def enable_streaming(func): |
