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

+25 -1
View File
@@ -19,7 +19,11 @@ from __future__ import annotations
import asyncio
import logging
import os
import socket
from datetime import datetime, timedelta, timezone
from logging.handlers import RotatingFileHandler
from pathlib import Path
from croniter import croniter
from procrastinate import App, PsycopgConnector
@@ -31,9 +35,29 @@ from politrack.core import registry
from politrack.core.runner import run
from politrack.db import connection
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
LOG_FORMAT = "%(asctime)s %(levelname)s %(name)s: %(message)s"
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
log = logging.getLogger("politrack.watchdog")
def _log_to_file() -> None:
"""Container logs vanish when a container is recreated (every deploy); keep a rotating copy in
$POLITRACK_LOG_DIR/<hostname>.log so failures can still be traced afterwards."""
log_dir = os.environ.get("POLITRACK_LOG_DIR")
if not log_dir:
return
try:
handler = RotatingFileHandler(Path(log_dir) / f"{socket.gethostname()}.log", maxBytes=20_000_000,
backupCount=5, encoding="utf-8")
except OSError as exc: # e.g. the host folder belongs to root: logs stay on stdout only
log.warning("cannot write logs to %s: %s", log_dir, exc)
return
handler.setFormatter(logging.Formatter(LOG_FORMAT))
logging.getLogger().addHandler(handler)
_log_to_file()
app = App(connector=PsycopgConnector(conninfo=get_settings().database_url))
TASKS: dict = {}
SCHEDULES: dict[str, str] = {}