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:
+8
-13
@@ -1,10 +1,11 @@
|
||||
"""Bzzoiro 数据源:抓取 + 入库(单一数据源)—— 聚合门面。
|
||||
|
||||
实现按管线拆分(单文件 → 多模块),本模块只做再导出,保持两个不变量:
|
||||
实现按管线拆分(单文件 → 多模块),本模块只做再导出,保持不变量:
|
||||
1. sources._load_sources() 仍从本模块导入 BzzoiroSource(注册表入口不变);
|
||||
2. 测试与脚本对 `bz.<名称>` 的 monkeypatch 语义不变 —— 子模块在运行期
|
||||
经本门面解析可替换协作者(抓取函数 / Bronze 写入助手 / REQUEST_INTERVAL),
|
||||
与拆分前的单文件行为一致。
|
||||
2. 测试与脚本对 `bz.<名称>` 的 monkeypatch 语义不变 —— 抓取函数 / REQUEST_INTERVAL
|
||||
仍经本门面解析可替换;Bronze 写入助手(_write_raw_event/_write_lineage/
|
||||
_safe_write_ingest_failure)已改为管线模块直接 import pipeline_write,
|
||||
测试需 patch `src.data.pipeline_write.*` 源模块。
|
||||
|
||||
三条管线(各自模块):
|
||||
1. events — 比赛日程/比分(/events/),含 source_event_id 血缘 → bzzoiro_events.py
|
||||
@@ -12,7 +13,8 @@
|
||||
3. stats — 已完赛比赛详细统计回填(/events/{id}/stats/) → bzzoiro_stats.py
|
||||
|
||||
共享基础:HTTP 抓取(多 key 轮换)与字段转换 → bzzoiro_common.py;
|
||||
Bronze 基础设施(RawEvent/IngestFailure/DataLineage)→ pipeline_write.py。
|
||||
Bronze 基础设施(RawEvent/IngestFailure/DataLineage)→ pipeline_write.py
|
||||
(各管线模块直接 import pipeline_write,不再经本门面转发)。
|
||||
|
||||
D4(工程债): Team/League/Match 的查找/创建经 Repository 层(src/db/repositories.py),
|
||||
各管线不直接控制事务(commit/rollback 由调用方 UnitOfWork 控制,只 flush)。
|
||||
@@ -31,6 +33,7 @@ from src.data.key_ring import _mask # noqa: F401 (R1 测试引用 bz._mask)
|
||||
from src.data.normalize import normalize_bzzoiro # noqa: F401
|
||||
|
||||
# ── 共享原语:HTTP 抓取 + 宽松字段转换 ──
|
||||
# NOTE: 管线模块同时从 bzzoiro_common 直接 import _fetch_json_async 等(经本处也转发)。
|
||||
from src.data.bzzoiro_common import ( # noqa: F401
|
||||
_fetch_json_async,
|
||||
_match_key,
|
||||
@@ -39,14 +42,6 @@ from src.data.bzzoiro_common import ( # noqa: F401
|
||||
_to_int_or_none,
|
||||
)
|
||||
|
||||
# ── 管线基础设施:RawEvent / IngestFailure / DataLineage ──
|
||||
from src.data.pipeline_write import ( # noqa: F401
|
||||
_safe_write_ingest_failure,
|
||||
_write_ingest_failure,
|
||||
_write_lineage,
|
||||
_write_raw_event,
|
||||
)
|
||||
|
||||
# ── events 管线:BzzoiroSource(注册表入口)+ 抓取/入库 ──
|
||||
from src.data.bzzoiro_events import ( # noqa: F401
|
||||
BzzoiroSource,
|
||||
|
||||
Reference in New Issue
Block a user