From 4edc4450e6fe578212600ad9733f0fa6eb3ffc9f Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Wed, 26 Feb 2025 17:29:26 +0300 Subject: 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. --- gn3/computations/streaming.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gn3/computations/streaming.py') 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): -- cgit 1.4.1