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:
simonandClaude Opus 5.5 committed 2026-11-13 00:46:18 +01:00
1 parent 79639e5319
commit 405c21a8c5
12 files changed
+251 -18

No files matched your search

+10 -2
View File
@@ -1,6 +1,14 @@
"""Read queries shared by the REST API and the MCP server (one module per domain)."""
from politrack.queries.admin import list_sources, list_topics, pending_claims, recent_runs, set_review, stats
from politrack.queries.admin import (
list_sources,
list_topics,
pending_claims,
recent_runs,
set_review,
source_freshness,
stats,
)
from politrack.queries.claims import calendar, list_claims, timeline_histogram
from politrack.queries.common import SourceFilter
from politrack.queries.money import list_money, money_summary, social_feed, wiki_edits
@@ -13,5 +21,5 @@ __all__ = [
"SourceFilter", "calendar", "former_overview", "get_organization", "get_party", "get_person", "list_claims",
"list_money", "list_organizations", "list_parties", "list_persons", "list_sources", "list_topics", "list_votes",
"money_summary", "pending_claims", "recent_runs", "person_network", "person_votes", "search", "set_review", "social_feed",
"stats", "timeline_histogram", "vote_detail", "wiki_edits",
"source_freshness", "stats", "timeline_histogram", "vote_detail", "wiki_edits",
]
+23
View File
@@ -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 "