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
@@ -26,6 +26,7 @@ from .account_supply_service import (
load_supply_snapshot_inventories,
supply_snapshot_max_age_seconds,
)
from .account_work_queue import STALE_RUNNING_SECONDS
from .external_order_source import get_cross_db_lookup_counts
TREND_DAYS = 7
@@ -495,6 +496,15 @@ def account_platform_status(
bucket[str(status)] = int(count or 0)
if status == "pending":
bucket["oldest_pending_due_at"] = oldest_due
if isinstance(oldest_due, datetime):
due_utc = (
oldest_due.replace(tzinfo=UTC)
if oldest_due.tzinfo is None
else oldest_due.astimezone(UTC)
)
bucket["oldest_pending_age_seconds"] = max(
0, int((moment - due_utc).total_seconds())
)
sync_domains: dict[str, dict[str, Any]] = {}
if include_diagnostics:
@@ -664,6 +674,29 @@ def account_platform_status(
"message": f"账号内部工作队列有 {overdue_work} 项待处理已过期",
}
)
stale_running_work = int(
db.query(func.count(AccountWorkItem.id))
.filter(
AccountWorkItem.status == "running",
AccountWorkItem.started_at.isnot(None),
AccountWorkItem.started_at
<= moment - timedelta(seconds=STALE_RUNNING_SECONDS),
)
.scalar()
or 0
)
if stale_running_work:
alerts.append(
{
"code": "account_work_stale_running",
"severity": "warning",
"count": stale_running_work,
"message": (
f"账号内部工作队列有 {stale_running_work} 项运行超过 "
f"{STALE_RUNNING_SECONDS // 60} 分钟未结束"
),
}
)
trends = _platform_trends(db, moment) if include_trends else None
if trends is not None: