feat: 累积功能变更 — 聊天集成、租户管理、小程序更新、ETL 增强、迁移脚本

包含多个会话的累积代码变更:
- backend: AI 聊天服务、触发器调度、认证增强、WebSocket、调度器最小间隔
- admin-web: ETL 状态页、任务管理、调度配置、登录优化
- miniprogram: 看板页面、聊天集成、UI 组件、导航更新
- etl: DWS 新任务(finance_area_daily/board_cache)、连接器增强
- tenant-admin: 项目初始化
- db: 19 个迁移脚本(etl_feiqiu 11 + zqyy_app 8)
- packages/shared: 枚举和工具函数更新
- tools: 数据库工具、报表生成、健康检查
- docs: PRD/架构/部署/合约文档更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Neo
2026-04-06 00:03:48 +08:00
parent 70324d8542
commit 6f8f12314f
515 changed files with 76604 additions and 7456 deletions

View File

@@ -14,10 +14,13 @@
from __future__ import annotations
import logging
import time
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from ..services.task_executor import task_executor
# CHANGE 2026-03-24 | dev-trace-log: WebSocket 连接生命周期追踪
from ..trace.ws_wrapper import ws_trace_connect, ws_trace_disconnect, ws_trace_message
logger = logging.getLogger(__name__)
@@ -37,13 +40,23 @@ async def ws_logs(websocket: WebSocket, execution_id: str) -> None:
await websocket.accept()
logger.info("WebSocket 连接已建立: execution_id=%s", execution_id)
# CHANGE 2026-03-24 | dev-trace-log: 记录 WS_CONNECT span
_t0 = time.perf_counter()
_ws_ctx = ws_trace_connect(execution_id, client_info=str(websocket.client))
_msg_count = 0
_total_bytes = 0
# 订阅日志流
queue = task_executor.subscribe(execution_id)
_disconnect_reason = "normal"
try:
# 回放已有的历史日志行
for line in task_executor.get_logs(execution_id):
await websocket.send_text(line)
_msg_count += 1
_total_bytes += len(line.encode("utf-8"))
ws_trace_message(_msg_count, _total_bytes)
# 如果任务已经不在运行且没有订阅者队列中的数据,
# 仍然保持连接等待——可能是任务刚结束但 queue 里还有未消费的消息
@@ -53,13 +66,21 @@ async def ws_logs(websocket: WebSocket, execution_id: str) -> None:
# 执行结束哨兵
break
await websocket.send_text(msg)
_msg_count += 1
_total_bytes += len(msg.encode("utf-8"))
ws_trace_message(_msg_count, _total_bytes)
except WebSocketDisconnect:
_disconnect_reason = "client_disconnect"
logger.info("WebSocket 客户端断开: execution_id=%s", execution_id)
except Exception:
_disconnect_reason = "error"
logger.exception("WebSocket 异常: execution_id=%s", execution_id)
finally:
task_executor.unsubscribe(execution_id, queue)
# CHANGE 2026-03-24 | dev-trace-log: 记录 WS_DISCONNECT span 并写入日志
_duration_ms = (time.perf_counter() - _t0) * 1000
ws_trace_disconnect(_disconnect_reason, _msg_count, _duration_ms)
# 安全关闭连接(客户端可能已断开,忽略错误)
try:
await websocket.close()