32 lines
714 B
Python
32 lines
714 B
Python
import asyncio
|
|
import logging
|
|
|
|
from app.config import get_settings
|
|
from app.db.base import SessionLocal
|
|
from app.reminders.fire import check_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:
|
|
check_due_reminders(db)
|
|
finally:
|
|
db.close()
|