"""Periodic job: send pending scheduled notifications via WebSocket.""" from app.database import async_session_factory from app.services.notification_service import get_pending_scheduled, mark_as_sent from app.services.ws_manager import manager async def send_pending_notifications(): async with async_session_factory() as db: pending = await get_pending_scheduled(db) for notif in pending: await mark_as_sent(db, notif.id) await db.commit() # Push via WebSocket await manager.send_to_user(notif.user_id, { "type": "new_notification", "notification": { "id": str(notif.id), "title": notif.title, "body": notif.body, "type": notif.type, "created_at": notif.created_at.isoformat(), }, })