"""Background thread that periodically prunes old logs / errors / forensics.""" import logging import threading import time import db from settings import RETENTION_RUN_INTERVAL_SECONDS logger = logging.getLogger("web.retention") def _loop(): while True: try: db.cleanup_retention() except Exception: logger.exception("retention cleanup failed") time.sleep(RETENTION_RUN_INTERVAL_SECONDS) def start() -> None: t = threading.Thread(target=_loop, name="retention", daemon=True) t.start() logger.info("retention thread started (interval=%ss)", RETENTION_RUN_INTERVAL_SECONDS)