update DB table
This commit is contained in:
@@ -32,8 +32,8 @@ def update_json_status(queue_id, task_id, status, result=None):
|
|||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def run_command_with_logging(cmd, log_file, cwd=None, env=None, timeout=1800):
|
def run_command_with_logging(cmd, log_file, cwd=None, env=None, timeout=1800, stop_string=None):
|
||||||
"""Runs a command, logs output to file and stdout with ISO timestamps and levels."""
|
"""Runs a command, logs output, and optionally stops when a string is found."""
|
||||||
if env is None:
|
if env is None:
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
if cwd is None:
|
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.write(log_line)
|
||||||
f.flush()
|
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
|
return process.returncode
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
iso_now = datetime.datetime.now().isoformat()
|
iso_now = datetime.datetime.now().isoformat()
|
||||||
@@ -122,10 +136,10 @@ def run_worker():
|
|||||||
checkout_cmd = f"./TPF/gitea_repo_controller.sh checkout {queue.source}"
|
checkout_cmd = f"./TPF/gitea_repo_controller.sh checkout {queue.source}"
|
||||||
run_command_with_logging(checkout_cmd, queue_log)
|
run_command_with_logging(checkout_cmd, queue_log)
|
||||||
|
|
||||||
# 1-5 Build software
|
# 1-5 Build software and run QEMU
|
||||||
# Explicitly use /bin/bash to avoid shell mismatch
|
# 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'"
|
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
|
# 9- Loop for each task
|
||||||
tasks = db.query(models.Task).filter(models.Task.queue_id == queue.id, models.Task.status == "Waiting").all()
|
tasks = db.query(models.Task).filter(models.Task.queue_id == queue.id, models.Task.status == "Waiting").all()
|
||||||
|
|||||||
Reference in New Issue
Block a user