import asyncio import logging from app.config import get_settings from app.db.base import SessionLocal from app.reminders_scoped.fire import process_due_reminders logger = logging.getLogger(__name__) WATCH_INTERVAL_SEC = 30 async def reminders_watcher_loop() -> None: while True: try: await asyncio.sleep(WATCH_INTERVAL_SEC) if not get_settings().reminders_enabled: continue await _tick() except asyncio.CancelledError: raise except Exception: logger.exception("Reminders watcher error") async def _tick() -> None: db = SessionLocal() try: await process_due_reminders(db) finally: db.close()