refactor: 管线写入依赖解耦——pipeline_write 直接 import
bzzoiro_events / bzzoiro_standings / bzzoiro_stats 直接 import src.data.pipeline_write(_write_raw_event/_write_lineage/_safe_write_ingest_failure), 删除 bzzoiro.py 门面中的 pipeline_write 转发胶水。 保留 fetch_*/_fetch_json_async/REQUEST_INTERVAL 经 bz. 门面调用(测试 monkeypatch 入口); 测试 best-effort 改为 patch 管线模块自身命名空间(from-import 绑定语义)。 函数语义与「失败不拖垮主流程」不变;source_record_id/transform_name 约定不变。 全量测试 270 通过。
This commit is contained in:
@@ -15,6 +15,7 @@ from datetime import datetime, timedelta, timezone
|
||||
|
||||
from src.data.bzzoiro_common import _to_float_or_none, _to_int_or_none
|
||||
from src.data.config import BZZOIRO_LEAGUE_IDS
|
||||
from src.data.pipeline_write import _safe_write_ingest_failure, _write_lineage, _write_raw_event
|
||||
from src.db.models import MatchStats
|
||||
from src.db.repositories import MatchRepository
|
||||
|
||||
@@ -90,7 +91,7 @@ async def ingest_bzzoiro_event_stats(
|
||||
|
||||
筛选条件: match_status=finished 且 source_event_id 非空。
|
||||
only_missing=True 时跳过已有统计的比赛(增量);False 则全量刷新。
|
||||
limit 控制单次最多处理的比赛数(上游限速 1.2s/请求,大批量需分次触发)。
|
||||
limit 控制单次最多处理的比赛数(上游限速约 1.2s/请求,大批量需分次触发)。
|
||||
"""
|
||||
from src.data import bzzoiro as bz
|
||||
|
||||
@@ -120,7 +121,7 @@ async def ingest_bzzoiro_event_stats(
|
||||
except Exception as e:
|
||||
logger.warning("stats fetch failed match=%s event=%s: %s", m.id, m.source_event_id, e)
|
||||
result["errors"].append(f"match {m.id}: {e}")
|
||||
await bz._safe_write_ingest_failure(
|
||||
await _safe_write_ingest_failure(
|
||||
db,
|
||||
entity_type="match_stats",
|
||||
source_record_id=str(m.source_event_id),
|
||||
@@ -165,8 +166,8 @@ async def ingest_bzzoiro_event_stats(
|
||||
# 管线基础设施:写入 RawEvent + DataLineage
|
||||
batch_id = f"bzzoiro-stats-{m.source_event_id}-{now.strftime('%Y%m%d%H%M%S')}"
|
||||
try:
|
||||
await bz._write_raw_event(db, "bzzoiro", str(m.source_event_id), payload, batch_id)
|
||||
await bz._write_lineage(db, "bzzoiro", str(m.source_event_id), "match_stats", m.stats.id if m.stats else None, "stats_backfill", {"match_id": m.id}, batch_id)
|
||||
await _write_raw_event(db, "bzzoiro", str(m.source_event_id), payload, batch_id)
|
||||
await _write_lineage(db, "bzzoiro", str(m.source_event_id), "match_stats", m.stats.id if m.stats else None, "stats_backfill", {"match_id": m.id}, batch_id)
|
||||
except Exception:
|
||||
pass # 基础设施写入失败不影响主流程
|
||||
|
||||
|
||||
Reference in New Issue
Block a user