Spaces:
Runtime error
Runtime error
File size: 1,010 Bytes
46085c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from __future__ import annotations
import asyncio
import logging
from app.core.config import get_settings
from app.db import AsyncSessionLocal
from app.queues import RabbitMQBroker
from app.repository import create_alert
from app.schemas import AlertEvent
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("cybully.alert_worker")
async def main() -> None:
settings = get_settings()
broker = RabbitMQBroker(settings)
async def handle(payload: dict) -> None:
event = AlertEvent.model_validate(payload)
async with AsyncSessionLocal() as session:
await create_alert(session, event)
logger.info(
"Stubbed alert for incident %s to %s",
event.incident_id,
event.recipient,
)
await broker.consume_json(settings.alert_dispatch_queue, handle)
logger.info("Alert worker consuming %s", settings.alert_dispatch_queue)
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())
|