fix: match crontab entries by script filename (underscore) not task name (hyphen)

This commit is contained in:
hmo
2026-07-19 09:25:25 +08:00
parent 0ed048c327
commit 94250e9dda
+8 -4
View File
@@ -832,9 +832,13 @@ def api_monitor():
else: else:
result["tier2"] = {"status": "no_data", "note": f"{t2_file} 不存在", "summary": {"ok": 0, "total": 0}} result["tier2"] = {"status": "no_data", "note": f"{t2_file} 不存在", "summary": {"ok": 0, "total": 0}}
# 定时任务状态 # 定时任务状态
expected_tasks = ["agents-health-check", "agents-daily-health", "agents-todo-executor"] expected_tasks = [
("agents-health-check", "agents_health_check.py"),
("agents-daily-health", "agents_daily_health.py"),
("agents-todo-executor", "self_todo_executor.py"),
]
if sys.platform == "win32": if sys.platform == "win32":
for name in expected_tasks: for name, filename in expected_tasks:
try: try:
r = subprocess.run(["schtasks", "/Query", "/TN", name, "/FO", "CSV", "/NH"], r = subprocess.run(["schtasks", "/Query", "/TN", name, "/FO", "CSV", "/NH"],
capture_output=True, text=True, timeout=5, capture_output=True, text=True, timeout=5,
@@ -845,10 +849,10 @@ def api_monitor():
result["tasks"].append({"name": name, "status": status}) result["tasks"].append({"name": name, "status": status})
else: else:
# Linux: 直接检查本地 crontab(不在 Windows 上跑了) # Linux: 直接检查本地 crontab(不在 Windows 上跑了)
for name in expected_tasks: for name, filename in expected_tasks:
try: try:
r = subprocess.run(["crontab", "-l"], capture_output=True, text=True, timeout=5) r = subprocess.run(["crontab", "-l"], capture_output=True, text=True, timeout=5)
if name in r.stdout: if filename in r.stdout:
result["tasks"].append({"name": name, "status": "cron_ok"}) result["tasks"].append({"name": name, "status": "cron_ok"})
else: else:
result["tasks"].append({"name": name, "status": "not_deployed"}) result["tasks"].append({"name": name, "status": "not_deployed"})