fix: 覆盖重生成失败后不再重复已成功日期

This commit is contained in:
Benature
2026-11-29 20:24:37 +08:00
parent 16811d5ec8
commit e2efcf900e
3 changed files with 44 additions and 6 deletions

View File

@ -59,8 +59,10 @@ def missing_message_dates(
overwrite: bool = False,
refresh_tagged_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
while current <= end:
output = Path(output_for_day(current))
@ -70,7 +72,11 @@ def missing_message_dates(
and current >= refresh_tagged_from
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):
yield current
current += timedelta(days=1)
@ -224,6 +230,15 @@ def main():
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 = {
"model": args.model,
"start_date": start.isoformat(),
@ -235,8 +250,8 @@ def main():
"failed": 0,
"last_completed": None,
"last_attempted": None,
"overwritten_dates": sorted(previous_overwritten),
}
state_path = Path(args.state).expanduser()
write_state(state_path, state)
print(
f"补日志范围: {daily_start} 至 {end};"
@ -244,7 +259,7 @@ def main():
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
write_state(state_path, state)
print(f"===== {label} 开始 =====", flush=True)
@ -259,6 +274,10 @@ def main():
state[key] += 1
state_key = {"daily": "last_completed", "weekly": "last_weekly_completed", "monthly": "last_monthly_completed"}[kind]
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)
print(f"===== {label} 完成 =====", flush=True)
return 0
@ -321,6 +340,7 @@ def main():
args.overwrite,
refresh_tagged_from,
daily_overwrite_from,
set(state["overwritten_dates"]),
):
command = [
sys.executable, str(ROOT / "lark_snooper.py"), "summarize",
@ -338,7 +358,9 @@ def main():
or (daily_overwrite_from and day >= daily_overwrite_from)
):
command.append("--overwrite")
result = run_step(command, output, f"补日志 {day}")
result = run_step(
command, output, f"补日志 {day}", kind="daily", day=day
)
if result:
return result