chore: purge checks older than 30 days
Build and deploy / build-deploy (push) Waiting to run

This commit is contained in:
Hermes Agent
2026-10-26 08:46:50 +00:00
parent 5c8c13891f
commit 3ac835ab7e
2 changed files with 43 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
"""Remove Arena check records older than the retention window."""
from __future__ import annotations
import os
import sqlite3
import sys
import time
from datetime import datetime, timedelta, timezone
DB_PATH = os.environ.get("DB_PATH", "/data/arena.db")
RETENTION_DAYS = int(os.environ.get("CHECK_RETENTION_DAYS", "30"))
def cleanup(db_path: str = DB_PATH, retention_days: int = RETENTION_DAYS) -> int:
if retention_days < 1:
raise ValueError("CHECK_RETENTION_DAYS must be >= 1")
cutoff = (datetime.now(timezone.utc) - timedelta(days=retention_days)).isoformat()
db = sqlite3.connect(db_path, timeout=30)
try:
db.execute("PRAGMA busy_timeout=30000")
before = db.total_changes
db.execute("BEGIN IMMEDIATE")
db.execute("DELETE FROM checks WHERE checked_at < ?", (cutoff,))
removed = db.total_changes - before
db.commit()
# Keep the persistent WAL bounded without a full VACUUM/long lock.
db.execute("PRAGMA wal_checkpoint(PASSIVE)")
print(f"[cleanup] removed={removed} cutoff={cutoff} retention_days={retention_days}")
return removed
except Exception:
db.rollback()
raise
finally:
db.close()
if __name__ == "__main__":
try:
cleanup()
except Exception as exc:
print(f"[cleanup] ERROR: {exc}", file=sys.stderr)
raise
+1
View File
@@ -17,6 +17,7 @@ umask 077
cat <<EOF | crontab - cat <<EOF | crontab -
0 */$INTERVAL * * * set -a; . $CRON_ENV; set +a; /usr/local/bin/python3 /app/app/probe.py >> /proc/1/fd/1 2>&1 0 */$INTERVAL * * * set -a; . $CRON_ENV; set +a; /usr/local/bin/python3 /app/app/probe.py >> /proc/1/fd/1 2>&1
15 3 * * * set -a; . $CRON_ENV; set +a; /usr/local/bin/python3 /app/app/cleanup.py >> /proc/1/fd/1 2>&1
EOF EOF
cron cron