spark_colony / core /notification.py
diwash-barla1's picture
refactor: decompose app into modular domain packages for v2.5
0f336cf
Raw
History Blame Contribute Delete
862 Bytes
from typing import Optional
from schemas.enums import NotificationLevel
from schemas.models import NotificationModel
from database.db import DatabaseManager
from telemetry.event_bus import EventBus
class NotificationEngine:
"""Central notification center managing persisted system alerts and WS events."""
def __init__(self, db: DatabaseManager, event_bus: EventBus):
self.db = db
self.event_bus = event_bus
async def notify(self, level: NotificationLevel, title: str, message: str, mission_id: Optional[str] = None) -> NotificationModel:
notif = NotificationModel(level=level, title=title, message=message, mission_id=mission_id)
await self.db.save_notification(notif)
await self.event_bus.emit("NotificationCreated", mission_id or "system", "NotificationEngine", notif.model_dump())
return notif