feat(health): cron列表加消息通道列+可切换API(toggle_delivery)

This commit is contained in:
xxm
2026-08-21 20:23:33 +08:00
parent 6577534130
commit d6e101c4df
2 changed files with 57 additions and 1 deletions
+34
View File
@@ -2472,6 +2472,40 @@ def api_broadcast_archive():
return jsonify({"ok": True})
@app.route("/api/broadcast/toggle_delivery", methods=["POST"])
def api_broadcast_toggle_delivery():
"""切换 cron job 的消息通道(broadcast/xmpp/both
payload: {"name": "job名称"} 或 {"script": "脚本名"}
"""
import json as _json
data = request.get_json(force=True) or {}
jobs_path = "/home/hmo/.hermes/profiles/position-analyst/cron/jobs.json"
with open(jobs_path, encoding="utf-8") as f:
jobs = _json.load(f)
update = None
for j in jobs.get("jobs", []):
if not isinstance(j, dict):
continue
match = False
if data.get("name") and j.get("name") == data.get("name"):
match = True
elif data.get("script") and str(j.get("script","")) == data.get("script"):
match = True
if match:
# 循环切换
cur = j.get("delivery", "broadcast")
nxt = {"broadcast":"xmpp", "xmpp":"both", "both":"broadcast"}.get(cur, "broadcast")
j["delivery"] = nxt
update = {"name": j.get("name"), "script": j.get("script"), "delivery": nxt}
break
if update:
with open(jobs_path, "w", encoding="utf-8") as f:
_json.dump(jobs, f, ensure_ascii=False, indent=2)
return jsonify({"ok": True, "job": update})
return jsonify({"ok": False, "error": "job not found"})
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8899))
print(f"🚀 MoFin Dashboard → http://0.0.0.0:{port}")