From 69be5dfe5272b4883d33249f5b845fbb5839e155 Mon Sep 17 00:00:00 2001 From: mahmamdouh Date: Sun, 28 Dec 2025 03:15:12 +0100 Subject: [PATCH] update DB table --- testarena_app/worker.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/testarena_app/worker.py b/testarena_app/worker.py index 394beb8..2696eb1 100644 --- a/testarena_app/worker.py +++ b/testarena_app/worker.py @@ -32,8 +32,8 @@ def update_json_status(queue_id, task_id, status, result=None): import datetime import time -def run_command_with_logging(cmd, log_file, cwd=None, env=None, timeout=1800): - """Runs a command, logs output to file and stdout with ISO timestamps and levels.""" +def run_command_with_logging(cmd, log_file, cwd=None, env=None, timeout=1800, stop_string=None): + """Runs a command, logs output, and optionally stops when a string is found.""" if env is None: env = os.environ.copy() if cwd is None: @@ -88,6 +88,20 @@ def run_command_with_logging(cmd, log_file, cwd=None, env=None, timeout=1800): f.write(log_line) f.flush() + # Check for stop string + if stop_string and stop_string in line: + iso_now = datetime.datetime.now().isoformat() + stop_msg = f"[{iso_now}] [INFO] Stop string '{stop_string}' detected. Terminating process.\n" + print(stop_msg, end="") + f.write(stop_msg) + f.flush() + process.terminate() + try: + process.wait(timeout=5) + except subprocess.TimeoutExpired: + process.kill() + return 0 + return process.returncode except Exception as e: iso_now = datetime.datetime.now().isoformat() @@ -122,10 +136,10 @@ def run_worker(): checkout_cmd = f"./TPF/gitea_repo_controller.sh checkout {queue.source}" run_command_with_logging(checkout_cmd, queue_log) - # 1-5 Build software - # Explicitly use /bin/bash to avoid shell mismatch + # 1-5 Build software and run QEMU + # We stop when we see the multicore app start message build_cmd = f"/bin/bash -c 'source $HOME/esp/esp-idf/export.sh && cd TPF/Sensor_hub_repo && idf.py build && idf.py qemu'" - run_command_with_logging(build_cmd, queue_log) + run_command_with_logging(build_cmd, queue_log, stop_string="cpu_start: Multicore app") # 9- Loop for each task tasks = db.query(models.Task).filter(models.Task.queue_id == queue.id, models.Task.status == "Waiting").all()