New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -10,7 +10,6 @@ from fastapi import FastAPI
from sqlalchemy import text
from app.core.config import settings
from app.core.database import database_manager
from app.services.messaging import setup_messaging, cleanup_messaging
from app.services.forecasting_alert_service import ForecastingAlertService
from shared.service_base import StandardFastAPIService
@@ -49,6 +48,8 @@ class ForecastingService(StandardFastAPIService):
]
self.alert_service = None
self.rabbitmq_client = None
self.event_publisher = None
# Create custom checks for alert service
async def alert_service_check():
@@ -103,20 +104,38 @@ class ForecastingService(StandardFastAPIService):
)
async def _setup_messaging(self):
"""Setup messaging for forecasting service"""
await setup_messaging()
self.logger.info("Messaging initialized")
"""Setup messaging for forecasting service using unified messaging"""
from shared.messaging import UnifiedEventPublisher, RabbitMQClient
try:
self.rabbitmq_client = RabbitMQClient(settings.RABBITMQ_URL, service_name="forecasting-service")
await self.rabbitmq_client.connect()
# Create unified event publisher
self.event_publisher = UnifiedEventPublisher(self.rabbitmq_client, "forecasting-service")
self.logger.info("Forecasting service unified messaging setup completed")
except Exception as e:
self.logger.error("Failed to setup forecasting unified messaging", error=str(e))
raise
async def _cleanup_messaging(self):
"""Cleanup messaging for forecasting service"""
await cleanup_messaging()
try:
if self.rabbitmq_client:
await self.rabbitmq_client.disconnect()
self.logger.info("Forecasting service messaging cleanup completed")
except Exception as e:
self.logger.error("Error during forecasting messaging cleanup", error=str(e))
async def on_startup(self, app: FastAPI):
"""Custom startup logic for forecasting service"""
# Initialize forecasting alert service
self.alert_service = ForecastingAlertService(settings)
await self.alert_service.start()
self.logger.info("Forecasting alert service initialized")
await super().on_startup(app)
# Initialize forecasting alert service with EventPublisher
if self.event_publisher:
self.alert_service = ForecastingAlertService(self.event_publisher)
await self.alert_service.start()
self.logger.info("Forecasting alert service initialized")
else:
self.logger.error("Event publisher not initialized, alert service unavailable")
async def on_shutdown(self, app: FastAPI):