Skip to content

Commit e62c19e

Browse files
Pigbibiclaude
andauthored
feat(health): /health 端点添加关键模块导入自检 (#244)
特别添加了 runtime_config_support 和 runtime_execution_policy 的导入检查, 这两个模块是本次三个服务全部挂掉的直接原因。 Co-authored-by: Claude <noreply@anthropic.com>
1 parent a80e141 commit e62c19e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Runs on Cloud Run; token from Secret Manager, orders via LongPort OpenAPI, alerts via Telegram.
55
"""
66
import json
7+
import importlib
78
import os
89
import time
910
import traceback
@@ -846,6 +847,20 @@ def request_method() -> str:
846847

847848
@app.route("/health", methods=["GET"])
848849
def health():
850+
critical_errors: list[str] = []
851+
for module_path in (
852+
"application.runtime_composer",
853+
"application.runtime_reporting_adapters",
854+
"application.runtime_strategy_adapters",
855+
"runtime_config_support",
856+
"runtime_execution_policy",
857+
):
858+
try:
859+
importlib.import_module(module_path)
860+
except Exception as exc:
861+
critical_errors.append(f"{module_path}: {type(exc).__name__}: {exc}")
862+
if critical_errors:
863+
return json.dumps({"status": "unhealthy", "errors": critical_errors}, ensure_ascii=False), 500
849864
return "OK", 200
850865

851866

0 commit comments

Comments
 (0)