Backups, freshness monitoring, persistent logs, procurement cleanup
- backup service: nightly pg_dump with retention, recorded as a run
- GET /api/v1/status/sources: 503 when a scheduled source or the backup
missed its last two slots (for Uptime Kuma)
- worker logs to ${DATA_DIR}/logs, so they survive redeploys
- procurement: reject implausible award dates (1900, contract end dates),
skip placeholder contractors, credit framework agreements to the BBG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79639e5319
commit
405c21a8c5
12 files changed
+251
-18
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from psycopg import Connection
|
||||
|
||||
|
||||
@@ -61,6 +63,27 @@ def stats(conn: Connection) -> dict:
|
||||
).fetchone()
|
||||
|
||||
|
||||
def source_freshness(conn: Connection, schedules: dict[str, str], now: datetime | None = None) -> list[dict]:
|
||||
"""Last successful run per scheduled task. Stale = its two latest scheduled slots passed without a
|
||||
successful run (plus an hour's grace for long runs), so one slow or failed run alone never alerts."""
|
||||
from croniter import croniter
|
||||
|
||||
now = now or datetime.now(timezone.utc)
|
||||
last_ok = {r["adapter"]: r["at"] for r in conn.execute(
|
||||
"SELECT adapter, max(COALESCE(finished_at, started_at)) AS at FROM run "
|
||||
"WHERE status IN ('ok', 'partial') GROUP BY adapter")}
|
||||
rows = []
|
||||
for name, schedule in sorted(schedules.items()):
|
||||
it = croniter(schedule, now)
|
||||
due = it.get_prev(datetime)
|
||||
before = it.get_prev(datetime)
|
||||
deadline = before - timedelta(hours=1)
|
||||
last = last_ok.get(name)
|
||||
rows.append({"adapter": name, "schedule": schedule, "last_success": last.isoformat() if last else None,
|
||||
"stale": last is None or last < deadline, "latest_slot": due.isoformat()})
|
||||
return rows
|
||||
|
||||
|
||||
def recent_runs(conn: Connection, limit: int = 50) -> list[dict]:
|
||||
return conn.execute(
|
||||
"SELECT adapter, mode, status, started_at, finished_at, stats, left(error, 2000) AS error FROM run "
|
||||
|
||||
Reference in new issue
Block a user