fix(douyu): 修复斗鱼链路 P0/P1 隐患并增强 P2 运维队列可观测性

This commit is contained in:
yml
2026-11-29 14:10:24 +08:00
parent be7146a9ef
commit d12d9e02b3
51 changed files with 2510 additions and 561 deletions
+23 -4
View File
@@ -193,7 +193,13 @@ async def supplier_recharge_callback(request: Request, db: Session = Depends(get
except FishFinRechargeConfigError as exc:
logger.error("[douyu] 供应商直充回调配置无效: {}", exc)
raise HTTPException(status_code=503, detail="供应商直充回调未配置") from exc
if not client.verify_response_sign(payload, "POST"):
try:
verified = client.verify_response_sign(payload, "POST")
finally:
close = getattr(client, "close", None)
if callable(close):
close()
if not verified:
logger.warning("[douyu] 供应商直充回调验签失败: keys={}", sorted(payload))
raise HTTPException(status_code=401, detail="供应商回调签名无效")
@@ -1285,14 +1291,19 @@ def list_live_goods(
"""实时读取精英宝典活动商品,不依赖账号或本地刷新任务。"""
del current
config = ensure_douyu_config(db)
client = activity_client()
try:
goods = query_activity_goods(
activity_client(),
client,
manual_id=str(douyu_config_value("manual_id", config.manual_id)),
rid=str(douyu_config_value("rid", config.rid)),
)
except DouyuActivityError as exc:
raise HTTPException(status_code=502, detail=f"活动商品加载失败:{exc}") from exc
finally:
close = getattr(client, "close", None)
if callable(close):
close()
now = datetime.now(UTC)
return [
DouyuGoodsOut(
@@ -1858,10 +1869,18 @@ def cleanup_orphan_tasks(
db: Session = Depends(get_db),
current: User = Depends(require_permission("douyu:task")),
):
"""手动清理没有内存执行器接管的斗鱼任务。"""
"""手动清理没有内存执行器或持久队列接管的斗鱼任务。"""
durable_batch_ids = {
str(batch_id)
for (batch_id,) in (
db.query(ExecutionJob.batch_id)
.filter(ExecutionJob.status.in_((STATUS_QUEUED, STATUS_RUNNING)))
.all()
)
}
cleaned = cleanup_orphan_douyu_tasks(
db,
active_batch_ids=douyu_batch_registry.active_ids(),
active_batch_ids=douyu_batch_registry.active_ids() | durable_batch_ids,
statuses=DOUYU_ACTIVE_TASK_STATUSES,
message="任务已中断(无执行器接管)",
)