fix: 覆盖重生成失败后不再重复已成功日期
This commit is contained in:
@ -59,8 +59,10 @@ def missing_message_dates(
|
|||||||
overwrite: bool = False,
|
overwrite: bool = False,
|
||||||
refresh_tagged_from: date | None = None,
|
refresh_tagged_from: date | None = None,
|
||||||
daily_overwrite_from: date | None = None,
|
daily_overwrite_from: date | None = None,
|
||||||
|
already_overwritten: set[str] | None = None,
|
||||||
):
|
):
|
||||||
"""Yield message days that are missing or explicitly tagged for refresh."""
|
"""Yield message days that are missing, tagged, or pending overwrite."""
|
||||||
|
overwritten = already_overwritten or set()
|
||||||
current = start
|
current = start
|
||||||
while current <= end:
|
while current <= end:
|
||||||
output = Path(output_for_day(current))
|
output = Path(output_for_day(current))
|
||||||
@ -70,7 +72,11 @@ def missing_message_dates(
|
|||||||
and current >= refresh_tagged_from
|
and current >= refresh_tagged_from
|
||||||
and has_missing_report_tag(output)
|
and has_missing_report_tag(output)
|
||||||
)
|
)
|
||||||
forced = daily_overwrite_from is not None and current >= daily_overwrite_from
|
forced = (
|
||||||
|
daily_overwrite_from is not None
|
||||||
|
and current >= daily_overwrite_from
|
||||||
|
and current.isoformat() not in overwritten
|
||||||
|
)
|
||||||
if (overwrite or not exists or refresh or forced) and has_messages(current):
|
if (overwrite or not exists or refresh or forced) and has_messages(current):
|
||||||
yield current
|
yield current
|
||||||
current += timedelta(days=1)
|
current += timedelta(days=1)
|
||||||
@ -224,6 +230,15 @@ def main():
|
|||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
state_path = Path(args.state).expanduser()
|
||||||
|
previous_overwritten: set[str] = set()
|
||||||
|
if state_path.exists():
|
||||||
|
try:
|
||||||
|
previous = json.loads(state_path.read_text(encoding="utf-8"))
|
||||||
|
previous_overwritten = set(previous.get("overwritten_dates", []))
|
||||||
|
except (ValueError, OSError):
|
||||||
|
previous_overwritten = set()
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
"model": args.model,
|
"model": args.model,
|
||||||
"start_date": start.isoformat(),
|
"start_date": start.isoformat(),
|
||||||
@ -235,8 +250,8 @@ def main():
|
|||||||
"failed": 0,
|
"failed": 0,
|
||||||
"last_completed": None,
|
"last_completed": None,
|
||||||
"last_attempted": None,
|
"last_attempted": None,
|
||||||
|
"overwritten_dates": sorted(previous_overwritten),
|
||||||
}
|
}
|
||||||
state_path = Path(args.state).expanduser()
|
|
||||||
write_state(state_path, state)
|
write_state(state_path, state)
|
||||||
print(
|
print(
|
||||||
f"补日志范围: {daily_start} 至 {end};"
|
f"补日志范围: {daily_start} 至 {end};"
|
||||||
@ -244,7 +259,7 @@ def main():
|
|||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def run_step(command, output, label, kind="daily"):
|
def run_step(command, output, label, kind="daily", day: date | None = None):
|
||||||
state["last_attempted"] = label
|
state["last_attempted"] = label
|
||||||
write_state(state_path, state)
|
write_state(state_path, state)
|
||||||
print(f"===== {label} 开始 =====", flush=True)
|
print(f"===== {label} 开始 =====", flush=True)
|
||||||
@ -259,6 +274,10 @@ def main():
|
|||||||
state[key] += 1
|
state[key] += 1
|
||||||
state_key = {"daily": "last_completed", "weekly": "last_weekly_completed", "monthly": "last_monthly_completed"}[kind]
|
state_key = {"daily": "last_completed", "weekly": "last_weekly_completed", "monthly": "last_monthly_completed"}[kind]
|
||||||
state[state_key] = label
|
state[state_key] = label
|
||||||
|
if day is not None:
|
||||||
|
overwritten = set(state.get("overwritten_dates", []))
|
||||||
|
overwritten.add(day.isoformat())
|
||||||
|
state["overwritten_dates"] = sorted(overwritten)
|
||||||
write_state(state_path, state)
|
write_state(state_path, state)
|
||||||
print(f"===== {label} 完成 =====", flush=True)
|
print(f"===== {label} 完成 =====", flush=True)
|
||||||
return 0
|
return 0
|
||||||
@ -321,6 +340,7 @@ def main():
|
|||||||
args.overwrite,
|
args.overwrite,
|
||||||
refresh_tagged_from,
|
refresh_tagged_from,
|
||||||
daily_overwrite_from,
|
daily_overwrite_from,
|
||||||
|
set(state["overwritten_dates"]),
|
||||||
):
|
):
|
||||||
command = [
|
command = [
|
||||||
sys.executable, str(ROOT / "lark_snooper.py"), "summarize",
|
sys.executable, str(ROOT / "lark_snooper.py"), "summarize",
|
||||||
@ -338,7 +358,9 @@ def main():
|
|||||||
or (daily_overwrite_from and day >= daily_overwrite_from)
|
or (daily_overwrite_from and day >= daily_overwrite_from)
|
||||||
):
|
):
|
||||||
command.append("--overwrite")
|
command.append("--overwrite")
|
||||||
result = run_step(command, output, f"补日志 {day}")
|
result = run_step(
|
||||||
|
command, output, f"补日志 {day}", kind="daily", day=day
|
||||||
|
)
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@ -97,3 +97,19 @@ def test_backfill_does_not_probe_days_that_do_not_need_regeneration(tmp_path):
|
|||||||
|
|
||||||
assert days == []
|
assert days == []
|
||||||
assert probes == [] # 已存在且无需重生成的日子不应触发拉取判断
|
assert probes == [] # 已存在且无需重生成的日子不应触发拉取判断
|
||||||
|
|
||||||
|
|
||||||
|
def test_daily_overwrite_skips_dates_already_overwritten(tmp_path):
|
||||||
|
for day in (date(2026, 11, 11), date(2026, 11, 12)):
|
||||||
|
(tmp_path / f"{day.isoformat()}.md").write_text("旧日报", encoding="utf-8")
|
||||||
|
|
||||||
|
days = list(missing_message_dates(
|
||||||
|
date(2026, 11, 11),
|
||||||
|
date(2026, 11, 12),
|
||||||
|
lambda day: True,
|
||||||
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
||||||
|
daily_overwrite_from=date(2026, 11, 11),
|
||||||
|
already_overwritten={"2026-11-11"},
|
||||||
|
))
|
||||||
|
|
||||||
|
assert days == [date(2026, 11, 12)]
|
||||||
|
|||||||
Reference in New Issue
Block a user