上游要的不只是网关记的任务状态镜像,还有「已登录账号在站点上的真实订单」,
但账号只在 NAT 后本地机上,只能经网关队列走。新增独立查询通道(§11):
- gateway 单开 account_queries 表 + QueryStatus 状态机,接口
POST /api/account/queries(幂等)/ lease / {id}/result / {id}
- 不复用下单任务队列:查询是只读,租约过期可安全重投(与下单「绝不自动
重投」相反),且不该被全局并发度 1 堵死、task_reports 是订单镜像不能污染
- 本地交易服务起第二条常驻循环 query_runner,领到即调 SiteInteractor 真读:
order_list 复用已实测的 list_recent_orders(规范化字段 + 站点
orderListData 原文),order_detail 复用 fetch_order_detail(配送阶段 +
页面 __INITIAL_STATE__ 原样透传,结构未经真实样本,不抽字段)
- 账号级串行仍由 SiteInteractor 的锁保证;每次执行套超时按失败回报
- 错误码 6005/6006(查询通道,可重试只读区别于 6001-6004);/health 暴露
queued_query_count;结果体积上限先丢原始 JSON
openapi.json 重导,docs/order-gateway.md §11、README、.env.example 补全
配置与实测边界。全量测试 404→454 通过。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
"""网关健康检查路由"""
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from app.gateway.container import GatewayContainer
|
|
from app.gateway.models import GatewayHealthData
|
|
from app.shared.api import ApiResponse, get_container
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
|
|
@router.get("/health", response_model=ApiResponse[GatewayHealthData])
|
|
async def health(
|
|
container: GatewayContainer = Depends(get_container),
|
|
) -> ApiResponse[GatewayHealthData]:
|
|
"""网关健康状态
|
|
|
|
只做规格 §4.7 的两条兜底告警:worker 失联、任务长时间无人领。
|
|
付款期限监控不在网关——本地机 7×24 在线,那套逻辑放本地。
|
|
另外带上账号只读查询的积压数量:它不参与告警判定(查询有自己的 TTL 会自动
|
|
expired),只是给运维一个可见信号。
|
|
"""
|
|
data = await container.task_queue.health_snapshot()
|
|
data.queued_query_count = await container.query_queue.queued_count()
|
|
return ApiResponse[GatewayHealthData](
|
|
success=True, msg="success", data=data, code=0
|
|
)
|