fix: cron健康监控发现问题→写TODO供自愈处理

This commit is contained in:
知微
2026-07-09 13:53:12 +08:00
parent 87b795f353
commit 3878404a80
+19 -1
View File
@@ -44,8 +44,24 @@ def xmpp_push(text):
print(f"[XMPP推送失败] {e}", file=sys.stderr)
return False
def _create_cron_todo(tname, desc):
"""为故障cron创建TODO供自愈处理"""
try:
_c = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db", timeout=10)
_c.execute(
"INSERT OR REPLACE INTO todos (id, title, description, status, priority, source, fix_action, created_at) "
"VALUES (?, ?, ?, 'pending', 'high', 'cron_health', ?, datetime('now','localtime'))",
(f"cron_err_{tname.replace(' ','_')}", f"[CRON_ERROR] {tname}", desc,
f"cd /home/hmo/MoFin && python3 scripts/preflight_verify.py --cron-check")
)
_c.commit()
_c.close()
except Exception:
pass
def parse_time(ts_str):
"""解析ISO时间戳为datetime"""
if not ts_str:
return None
try:
@@ -147,6 +163,8 @@ def main():
if is_new_alert(key, state):
alerts.append(f"{j['name']}({j['id'][:8]}) [{tag}] {j['status']} @ {j['last_run'][:19]}")
state[key] = {"last_alerted": datetime.now().timestamp()}
# 同时写TODO供自愈系统处理
_create_cron_todo(j['name'], f"[CRON_ERROR] {j['name']} 状态={j['status']} 最后运行={j['last_run'][:19]}")
# ── 检查2:关键job空闲超时 ──
stale_jobs = check_idle(jobs)