- 拆包 fengxiang/:config/client/store/notify/monitor/admin/tts,统一入口 order_monitor.py - 服务器形态:Docker 常驻,Cookie 由本机登录后 POST 上传并热加载,不再依赖桌面弹窗 - 修复:首次启动重推历史订单、speak() 阻塞主循环、夜间 sleep 10h 不可中断 - 修复:test_push.py 残留 miservice 依赖(小爱已移除)、run_monitor.bat 写死盘符 - 配置化:webhook/shopId 移出源码(环境变量 > config.yaml > 默认值) - 可观测:滚动文件日志 + /healthz + Docker HEALTHCHECK + 告警冷却 - 飞书通道保留配置位,默认关闭(原 token 已失效 code=19001) - 新增 22 项单元测试(不联网)
37 lines
1020 B
Python
37 lines
1020 B
Python
"""容器健康检查:判断进程是否还"在干活",而不只是端口通。
|
|
|
|
规则:
|
|
- 夜间暂停 / 尚未建立 Cookie 校验 -> 视为健康(属于预期状态)
|
|
- 最近一次成功轮询距今超过 15 分钟(且不是夜间)-> 不健康,交给 Docker 重启
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
with urllib.request.urlopen("http://127.0.0.1:8089/healthz", timeout=5) as resp:
|
|
data = json.load(resp)
|
|
except Exception as exc: # noqa: BLE001
|
|
print(f"healthz 不可达: {exc}")
|
|
return 1
|
|
|
|
mode = data.get("mode")
|
|
age = data.get("last_poll_age_sec")
|
|
print(json.dumps(data, ensure_ascii=False))
|
|
|
|
if mode == "night":
|
|
return 0
|
|
if age is None:
|
|
# 启动阶段还没跑出第一轮,给 15 分钟宽限
|
|
return 0 if (data.get("uptime_sec") or 0) < 900 else 1
|
|
return 0 if age < 900 else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|