diff options
| author | Alexander_Kabui | 2025-02-26 17:29:26 +0300 |
|---|---|---|
| committer | Alexander_Kabui | 2025-02-26 17:29:26 +0300 |
| commit | 4edc4450e6fe578212600ad9733f0fa6eb3ffc9f (patch) | |
| tree | 039fe39e33d79bf41952dc087c0ba66f8cbc5bb6 | |
| parent | 89b941b3c858dbd8ed5d9f9041e45267ad0e437b (diff) | |
| download | genenetwork3-4edc4450e6fe578212600ad9733f0fa6eb3ffc9f.tar.gz | |
feat: Add utility function for reading files and improve logging
* Add `read_file(file_path)` utility function to streamline file reading. * Updated `run_process()` to return log contents instead of just the log file path.
| -rw-r--r-- | gn3/computations/streaming.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gn3/computations/streaming.py b/gn3/computations/streaming.py index 2b0a4e4..6e02694 100644 --- a/gn3/computations/streaming.py +++ b/gn3/computations/streaming.py @@ -5,6 +5,11 @@ from functools import wraps from flask import current_app, request +def read_file(file_path): + """Add utility function to read files""" + with open(file_path, "r", encoding="UTF-8") as file_handler: + return file_handler.read() + def run_process(cmd, log_file, run_id): """Function to execute an external process and capture the stdout in a file @@ -30,14 +35,14 @@ def run_process(cmd, log_file, run_id): process.wait() return {"msg": "success" if process.returncode == 0 else "Process failed", "run_id": run_id, - "log_file": log_file, + "log" : read_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, - "log_file": log_file} + "log" : read_file(log_file)} def enable_streaming(func): |
