Fix hub AI save: background PM2 restart after JSON response.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 23:06:31 +08:00
parent 823aeda42a
commit aaa72c7961
5 changed files with 32 additions and 21 deletions
+9 -4
View File
@@ -195,22 +195,27 @@ def apply_ai_env_to_all(updates: dict[str, str]) -> dict[str, Any]:
}
def restart_hub_and_instances_pm2() -> dict[str, Any]:
def restart_instances_then_hub_pm2() -> dict[str, Any]:
"""先重启三实例,最后重启中控(避免当前请求被中断)。"""
if not sys.platform.startswith("linux"):
return {"ok": False, "msg": "仅 Linux 服务器支持 PM2 重启", "results": []}
from lib.instance.instance_pm2_lib import restart_instance_pm2
apps = ["manual-trading-hub"]
results: list[dict[str, Any]] = []
hub_result = _restart_pm2_app("manual-trading-hub")
results.append({"app": "manual-trading-hub", **hub_result})
for ex in ("okx", "binance", "gate"):
r = restart_instance_pm2(ex)
results.append({"exchange": ex, **r})
hub_result = _restart_pm2_app("manual-trading-hub")
results.append({"app": "manual-trading-hub", **hub_result})
ok = all(r.get("ok") for r in results)
return {"ok": ok, "results": results}
def restart_hub_and_instances_pm2() -> dict[str, Any]:
"""兼容旧调用:与 restart_instances_then_hub_pm2 相同顺序。"""
return restart_instances_then_hub_pm2()
def _restart_pm2_app(app_name: str) -> dict[str, Any]:
try:
proc = subprocess.run(