feat: alert 补全 flow 名;AGENTS.md 补充 monitor 架构说明

This commit is contained in:
yeuimu
2026-08-27 09:45:28 +00:00
parent aa9a021ac4
commit 21057ea110
2 changed files with 21 additions and 3 deletions
+12 -3
View File
@@ -53,12 +53,21 @@ def _flow_run_id(event: dict) -> str | None:
def _fetch_run_detail(run_id: str) -> dict:
"""查 Prefect API 补全 flow run 权威信息,失败返回空 dict。"""
"""查 Prefect API 补全 flow run 权威信息(含 flow 名),失败返回空 dict。"""
api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api")
try:
resp = httpx.get(f"{api_url}/flow_runs/{run_id}", timeout=10)
resp.raise_for_status()
return resp.json()
detail = resp.json()
flow_id = detail.get("flow_id")
if flow_id:
try:
fresp = httpx.get(f"{api_url}/flows/{flow_id}", timeout=10)
fresp.raise_for_status()
detail["_flowName"] = fresp.json().get("name", "")
except Exception: # noqa: BLE001
detail["_flowName"] = ""
return detail
except Exception as err: # noqa: BLE001
print(f"[wecom-alert] 查询 flow run {run_id} 失败: {err}")
return {}
@@ -86,7 +95,7 @@ def wecom_alert_failure(event: dict | str | None = None) -> dict:
flow_name, run_name, state_msg, occurred = "", resource_name, "", ev.get("occurred", "")
if run_id:
detail = _fetch_run_detail(run_id)
flow_name = detail.get("name", "") or resource_name
flow_name = detail.get("_flowName") or resource_name
run_name = detail.get("name", "")
state = detail.get("state") or {}
state_msg = (state.get("message") or "").strip()