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
@@ -9,10 +9,12 @@ from sqlalchemy.orm import Session
from core.douyu import DouyuActivityClient
from ..database import release_idle_session
from ..models import Account
from .account_sync_service import (
DOMAIN_EXCHANGE_RECORDS,
get_sync_state,
lock_account_row,
record_sync_success,
)
from .business_events import record_official_exchange
@@ -74,6 +76,8 @@ def persist_official_exchange_records(
pairs: list[tuple[str, dict[str, Any]]],
) -> int:
"""把官方记录幂等补成账号事件,返回新写入数量。"""
if account.id is not None and pairs:
lock_account_row(db, int(account.id))
added = 0
for scope, record in pairs:
if not isinstance(record, dict):
@@ -195,7 +199,9 @@ def sync_exchange_records(
max_pages: int = 1,
) -> dict[str, Any]:
"""同步官方记录、补事件并保存可回放的按作用域原始投影。"""
account_id = int(account.id) if account.id is not None else None
observed_at = datetime.now(UTC)
released = release_idle_session(db)
pairs, errors = fetch_exchange_records(
client,
config,
@@ -203,6 +209,10 @@ def sync_exchange_records(
scopes=scopes,
max_pages=max_pages,
)
if released and account_id is not None:
account = db.get(Account, account_id) or account
if account.id is not None:
lock_account_row(db, int(account.id))
changed = persist_official_exchange_records(db, account, pairs)
previous = get_sync_state(
db,