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

@@ -27,14 +27,16 @@ from app.api import (
orchestrator, # NEW: Orchestrator integration endpoint
production_orders_operations, # Tenant deletion endpoints
audit,
ml_insights # ML insights endpoint
ml_insights, # ML insights endpoint
batch
)
from app.api.internal_alert_trigger import router as internal_alert_trigger_router
class ProductionService(StandardFastAPIService):
"""Production Service with standardized setup"""
expected_migration_version = "00001"
expected_migration_version = "001_initial_schema"
async def on_startup(self, app):
"""Custom startup logic including migration verification"""
@@ -63,6 +65,8 @@ class ProductionService(StandardFastAPIService):
]
self.alert_service = None
self.rabbitmq_client = None
self.event_publisher = None
# REMOVED: scheduler_service (replaced by Orchestrator Service)
# Create custom checks for services
@@ -84,22 +88,53 @@ class ProductionService(StandardFastAPIService):
expected_tables=production_expected_tables,
custom_health_checks={
"alert_service": check_alert_service
}
},
enable_messaging=True # Enable messaging support
)
async def _setup_messaging(self):
"""Setup messaging for production service using unified messaging"""
from shared.messaging import UnifiedEventPublisher, RabbitMQClient
try:
self.rabbitmq_client = RabbitMQClient(settings.RABBITMQ_URL, service_name="production-service")
await self.rabbitmq_client.connect()
# Create unified event publisher
self.event_publisher = UnifiedEventPublisher(self.rabbitmq_client, "production-service")
self.logger.info("Production service unified messaging setup completed")
except Exception as e:
self.logger.error("Failed to setup production unified messaging", error=str(e))
raise
async def _cleanup_messaging(self):
"""Cleanup messaging for production service"""
try:
if self.rabbitmq_client:
await self.rabbitmq_client.disconnect()
self.logger.info("Production service messaging cleanup completed")
except Exception as e:
self.logger.error("Error during production messaging cleanup", error=str(e))
async def on_startup(self, app: FastAPI):
"""Custom startup logic for production service"""
# Initialize alert service
self.alert_service = ProductionAlertService(settings)
# Initialize messaging
await self._setup_messaging()
# Initialize alert service with EventPublisher and database manager
self.alert_service = ProductionAlertService(self.event_publisher, self.database_manager)
await self.alert_service.start()
self.logger.info("Production alert service started")
# Store services in app state
app.state.alert_service = self.alert_service
app.state.production_alert_service = self.alert_service # Also store with this name for internal trigger
# REMOVED: Production scheduler service initialization
# Scheduling is now handled by the Orchestrator Service
# which calls our /generate-schedule endpoint
# Store services in app state
app.state.alert_service = self.alert_service
app.state.production_alert_service = self.alert_service # Also store with this name for internal trigger
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for production service"""
@@ -108,6 +143,9 @@ class ProductionService(StandardFastAPIService):
await self.alert_service.stop()
self.logger.info("Alert service stopped")
# Cleanup messaging
await self._cleanup_messaging()
def get_service_features(self):
"""Return production-specific features"""
return [
@@ -155,6 +193,7 @@ service.setup_custom_middleware()
# NOTE: Register more specific routes before generic parameterized routes
# IMPORTANT: Register audit router FIRST to avoid route matching conflicts
service.add_router(audit.router)
service.add_router(batch.router)
service.add_router(orchestrator.router) # NEW: Orchestrator integration endpoint
service.add_router(production_orders_operations.router) # Tenant deletion endpoints
service.add_router(quality_templates.router) # Register first to avoid route conflicts
@@ -166,6 +205,7 @@ service.add_router(production_dashboard.router)
service.add_router(analytics.router)
service.add_router(internal_demo.router)
service.add_router(ml_insights.router) # ML insights endpoint
service.add_router(internal_alert_trigger_router) # Internal alert trigger for demo cloning
# REMOVED: test_production_scheduler endpoint
# Production scheduling is now triggered by the Orchestrator Service