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
@@ -47,6 +47,7 @@ from .account_sync_service import (
DOMAIN_POINTS,
DOMAIN_ROLE,
DOMAIN_SESSION,
lock_account_row,
record_sync_success,
)
from .cookie_check_service import check_douyu_cookie, classify_douyu_cookie_result
@@ -755,6 +756,7 @@ def probe_account(
cookie = str(account.cookie or "").strip()
checked_at = _now()
errors: dict[str, str] = {}
owns_client = client is None
active_client = client or activity_client(
cookie,
logger_callback=logger_callback
@@ -764,6 +766,57 @@ def probe_account(
)
),
)
try:
return _probe_account_with_client(
account,
config_info,
active_client=active_client,
cookie=cookie,
checked_at=checked_at,
errors=errors,
session_checker=session_checker,
with_elite=with_elite,
with_esports=with_esports,
with_storehome=with_storehome,
with_eligibility=with_eligibility,
with_limited_goods=with_limited_goods,
with_gold=with_gold,
with_goods=with_goods,
with_elite_role=with_elite_role,
include_esports=include_esports,
include_peace=include_peace,
use_cache=use_cache,
cache_key=cache_key,
)
finally:
if owns_client:
close = getattr(active_client, "close", None)
if callable(close):
close()
def _probe_account_with_client(
account: Account,
config_info: dict[str, Any],
*,
active_client: DouyuActivityClient,
cookie: str,
checked_at: datetime,
errors: dict[str, str],
session_checker: Any,
with_elite: bool,
with_esports: bool,
with_storehome: bool,
with_eligibility: bool,
with_limited_goods: bool,
with_gold: bool,
with_goods: bool,
with_elite_role: bool,
include_esports: bool,
include_peace: bool,
use_cache: bool,
cache_key: str,
) -> dict[str, Any]:
if session_checker is _DEFAULT_SESSION_CHECKER:
session_checker = check_douyu_cookie
session = (
@@ -1121,6 +1174,9 @@ def persist_probe_result(
) -> None:
"""把一次探针结果写回账号和生命周期,是账号能力的唯一落库入口。"""
now = _now()
if account.id is not None:
# 严格先锁 accounts 主行,再写 account_sync_states / account_sync_runs / account_events
lock_account_row(db, int(account.id))
identity = probe.get("identity") or {}
if identity.get("uid"):
account.uid = str(identity["uid"])[:32]