refactor: 重构为可部署到服务器的模块化结构(v5.0.0)

- 拆包 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 项单元测试(不联网)
This commit is contained in:
houhuan committed 2026-11-16 12:45:23 +08:00
1 parent ab6a2bb7ea
commit 4ee30399bf
30 files changed
+2410 -825

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
"""本地语音播报(仅本地 Windows 模式使用,容器内自动禁用)。
原来 speak() 是同步调用:IndexTTS2 首次加载模型要 1-2 分钟,合成每次几秒,
直接卡在轮询主循环里,导致监控间隔完全失真。这里改为后台线程 + 队列。
服务器(Linux/容器)没有声卡也不装 torch,所以此模块在非 Windows 上直接降级为 no-op。
"""
from __future__ import annotations
import logging
import queue
import sys
import threading
from typing import Optional
log = logging.getLogger("fengxiang.tts")
class Speaker:
def __init__(self, voice_prompt: str = "", enabled: bool = True):
self.enabled = bool(enabled) and sys.platform == "win32"
self.voice_prompt = voice_prompt or None
self._queue: "queue.Queue[Optional[str]]" = queue.Queue(maxsize=20)
self._thread: Optional[threading.Thread] = None
self._impl = None
if enabled and not self.enabled:
log.info("当前平台 %s 不支持本地播报,已自动禁用 TTS", sys.platform)
def start(self) -> None:
if not self.enabled or self._thread:
return
self._thread = threading.Thread(target=self._worker, name="tts", daemon=True)
self._thread.start()
def say(self, text: str) -> None:
"""非阻塞投递,队列满则丢弃并告警(绝不阻塞监控)。"""
if not self.enabled:
return
try:
self._queue.put_nowait(text)
except queue.Full:
log.warning("TTS 队列已满,丢弃本次播报")
def _worker(self) -> None:
while True:
text = self._queue.get()
if text is None:
return
try:
if self._impl is None:
from local_tts import speak as local_speak # 延迟导入,避免无依赖时启动失败
self._impl = local_speak
self._impl(text, voice_prompt=self.voice_prompt)
log.info("语音播报完成: %s", text)
except Exception as exc: # noqa: BLE001
log.error("语音播报失败: %s", exc)
def stop(self) -> None:
if not self.enabled:
return
try:
self._queue.put_nowait(None)
except queue.Full:
pass