fix(web): align trend ranges, next runs and preview task records

This commit is contained in:
kairee committed 2026-10-31 23:46:49 +08:00
1 parent 19572171b8
commit 257fbe009b
7 files changed
+139 -10

No files matched your search

+70
View File
@@ -254,6 +254,69 @@ def _insert_snapshot(
)
def _seed_task_records(conn: sqlite3.Connection, latest_day: date) -> None:
"""写入可读的最近任务状态,让预览系统页有内容可看。"""
base = _timestamp(latest_day, hour=0, minute=1)
records = {
"snapshot": {
"name": "snapshot", "ok": True,
"started_at": int(base),
"finished_at": int(base + 1124),
"error": None,
"summary": {
"stat_date": latest_day.isoformat(), "total": 796, "ok": 796,
"failed": 0, "removed": 0, "completed": True,
"backup_path": f"data/backup/app-{latest_day.strftime('%Y%m%d')}.db",
},
},
"folder_sync": {
"name": "folder_sync", "ok": True,
"started_at": int(base + 20 * 3600),
"finished_at": int(base + 20 * 3600 + 8),
"error": None,
"summary": {"folders": 2, "added": 65, "removed": 0, "ok": True},
},
"discovery": {
"name": "discovery", "ok": True,
"started_at": int(base + 21 * 3600),
"finished_at": int(base + 21 * 3600 + 24),
"error": None,
"summary": {
"searches": 4, "items": 168, "candidates": 4,
"notified": 3, "errors": [],
},
},
"candidate_cleanup": {
"name": "candidate_cleanup", "ok": True,
"started_at": int(base + 22 * 3600),
"finished_at": int(base + 22 * 3600 + 1),
"error": None,
"summary": {"candidates_removed": 0, "fav_actions_expired": 0},
},
}
for name, record in records.items():
conn.execute(
"INSERT OR REPLACE INTO kv(k, v) VALUES (?, ?)",
(f"task:last:{name}", json.dumps(record, ensure_ascii=False)),
)
conn.execute(
"INSERT OR REPLACE INTO kv(k, v) VALUES ('snapshot:last_attempt', ?)",
(latest_day.isoformat(),),
)
conn.execute(
"INSERT OR REPLACE INTO kv(k, v) VALUES ('snapshot:last_completed', ?)",
(latest_day.isoformat(),),
)
conn.execute(
"INSERT OR REPLACE INTO kv(k, v) VALUES (?, '1')",
(f"snapshot:backup:{latest_day.isoformat()}",),
)
conn.execute(
"INSERT OR REPLACE INTO kv(k, v) VALUES (?, '')",
(f"snapshot:backup_error:{latest_day.isoformat()}",),
)
def _seed_blacklist(conn: sqlite3.Connection, now: float) -> None:
conn.execute(
"""
@@ -495,6 +558,7 @@ def seed_preview(
up_rows = _seed_up_stats(conn, latest_day, days, anomaly_rng)
_seed_candidates(conn, latest_day)
_seed_blacklist(conn, _timestamp(latest_day, hour=14))
_seed_task_records(conn, latest_day)
else:
up_rows = 0
conn.execute("DELETE FROM candidate WHERE channel = 'preview'")
@@ -635,6 +699,12 @@ def main(argv: Sequence[str] | None = None) -> int:
config_out=args.config_out,
with_anomalies=not args.no_anomalies,
)
except PermissionError as exc:
print(json.dumps({
"ok": False,
"error": f"目标数据库被占用,请先停止预览服务: {exc}",
}, ensure_ascii=False))
return 2
except (ValueError, FileNotFoundError, FileExistsError, RuntimeError, sqlite3.Error) as exc:
print(json.dumps({"ok": False, "error": str(exc)}, ensure_ascii=False))
return 2