fix(data): daily增量marker按日折叠——首日全量done后次日整段跳过增量的day-2致命坑 [nas]
09-07 首跑夜复查发现: daily ann/news marker 无日期维度,首跑日已写满 6168+6168 → 次日 06:00 首班会整段跳过增量采集,且 backfill 仍在跑会掩盖 症状。修=unit 名前挂 dt=YYYY-MM-DD/ 子目录(_dunit)+日初清旧日目录与 历史平铺 marker(_prune_daily_increment_markers);fulltext/pdf 段键=内容 id(不可变一次永逸)保持平铺不走折叠。契约测试: 次日重新拉窗承接新公告/ 当日断点续传不变/旧日目录日初清。
This commit is contained in:
@@ -724,6 +724,30 @@ def _save_depth(ctx):
|
||||
|
||||
# ---------- daily lane ----------
|
||||
|
||||
def _dunit(code, day):
|
||||
"""daily 增量段(ann/news) marker 单元名: 按日折叠(dt=YYYY-MM-DD/ 子目录)。
|
||||
增量窗每日一新,断点续传只保护当日——无日期维度会让首日全量 done 后次日
|
||||
整段跳过增量采集(09-07 首跑夜抓到的 day-2 坑)。fulltext/pdf 段键=内容 id
|
||||
(公告/文章不可变),保持平铺一次永逸,不走本折叠。"""
|
||||
return f"dt={day.isoformat()}/{code}"
|
||||
|
||||
|
||||
def _prune_daily_increment_markers():
|
||||
"""daily 日初清理: ann/news 增量 marker 只留今日 dt= 目录,并清历史遗留的
|
||||
平铺 *.done(首跑日产物,无日期维度)——两者都是次日跳过坑与无限增长防线。"""
|
||||
today = dt.date.today().isoformat()
|
||||
for stage in ("ann", "news"):
|
||||
d = CORPUS_ROOT / "state" / "markers" / "daily" / stage
|
||||
if not d.exists():
|
||||
continue
|
||||
for child in d.iterdir():
|
||||
if child.is_dir():
|
||||
if child.name != f"dt={today}":
|
||||
shutil.rmtree(child, ignore_errors=True)
|
||||
elif child.suffix == ".done":
|
||||
child.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def _run_ann_increment(ctx, pool, cl_cn, ledgers, recents):
|
||||
ctx.reset_stage()
|
||||
today = dt.date.today()
|
||||
@@ -732,7 +756,7 @@ def _run_ann_increment(ctx, pool, cl_cn, ledgers, recents):
|
||||
candidates = []
|
||||
for code, org in pool:
|
||||
if ctx.limit is None:
|
||||
if is_done(ctx.lane, "ann", code):
|
||||
if is_done(ctx.lane, "ann", _dunit(code, today)):
|
||||
continue
|
||||
elif ctx.budget_exhausted():
|
||||
break
|
||||
@@ -756,16 +780,17 @@ def _run_ann_increment(ctx, pool, cl_cn, ledgers, recents):
|
||||
_record_depth(ctx, "ann", r["sec_code"] or code,
|
||||
(r["ann_time"] or "")[:10])
|
||||
log.info("ann %s: +%d/%d", code, len(new), len(rows))
|
||||
ctx.unit_done("ann", code, mark=ctx.limit is None)
|
||||
ctx.unit_done("ann", _dunit(code, today), mark=ctx.limit is None)
|
||||
ctx.stop_now()
|
||||
return candidates
|
||||
|
||||
|
||||
def _run_news_increment(ctx, pool, cl_em, ledgers, recents, new_articles):
|
||||
ctx.reset_stage()
|
||||
today = dt.date.today()
|
||||
for code, _org in pool:
|
||||
if ctx.limit is None:
|
||||
if is_done(ctx.lane, "news", code):
|
||||
if is_done(ctx.lane, "news", _dunit(code, today)):
|
||||
continue
|
||||
elif ctx.budget_exhausted():
|
||||
break
|
||||
@@ -787,7 +812,7 @@ def _run_news_increment(ctx, pool, cl_em, ledgers, recents, new_articles):
|
||||
_record_depth(ctx, "news", code, (r["show_time"] or "")[:10])
|
||||
new_articles.append((r["art_code"], r["url"], r["show_time"]))
|
||||
log.info("news %s: +%d/%d", code, len(new), len(rows))
|
||||
ctx.unit_done("news", code, mark=ctx.limit is None)
|
||||
ctx.unit_done("news", _dunit(code, today), mark=ctx.limit is None)
|
||||
ctx.stop_now()
|
||||
|
||||
|
||||
@@ -921,6 +946,7 @@ def run_daily(ctx, pool):
|
||||
ctx.clients = {"cninfo": cl_cn, "eastmoney": cl_em, "article": cl_art}
|
||||
ctx.set_stores(ledgers)
|
||||
_reconcile_ledgers(ledgers, recents)
|
||||
_prune_daily_increment_markers()
|
||||
candidates = _run_ann_increment(ctx, pool, cl_cn, ledgers, recents)
|
||||
_run_news_increment(ctx, pool, cl_em, ledgers, recents, new_articles := [])
|
||||
_run_fulltext(ctx, cl_art, ledgers, recents, new_articles)
|
||||
|
||||
Reference in New Issue
Block a user