New alert service
This commit is contained in:
@@ -13,9 +13,11 @@ from app.core.database import database_manager
|
||||
from app.services.inventory_alert_service import InventoryAlertService
|
||||
from app.consumers.delivery_event_consumer import DeliveryEventConsumer
|
||||
from shared.service_base import StandardFastAPIService
|
||||
from shared.messaging import UnifiedEventPublisher
|
||||
import asyncio
|
||||
|
||||
from app.api import (
|
||||
batch,
|
||||
ingredients,
|
||||
stock_entries,
|
||||
transformations,
|
||||
@@ -79,10 +81,12 @@ class InventoryService(StandardFastAPIService):
|
||||
|
||||
async def _setup_messaging(self):
|
||||
"""Setup messaging for inventory service"""
|
||||
from shared.messaging.rabbitmq import RabbitMQClient
|
||||
from shared.messaging import RabbitMQClient
|
||||
try:
|
||||
self.rabbitmq_client = RabbitMQClient(settings.RABBITMQ_URL, service_name="inventory-service")
|
||||
await self.rabbitmq_client.connect()
|
||||
# Create event publisher
|
||||
self.event_publisher = UnifiedEventPublisher(self.rabbitmq_client, "inventory-service")
|
||||
self.logger.info("Inventory service messaging setup completed")
|
||||
except Exception as e:
|
||||
self.logger.error("Failed to setup inventory messaging", error=str(e))
|
||||
@@ -105,13 +109,16 @@ class InventoryService(StandardFastAPIService):
|
||||
# Call parent startup (includes database, messaging, etc.)
|
||||
await super().on_startup(app)
|
||||
|
||||
# Initialize alert service
|
||||
alert_service = InventoryAlertService(settings)
|
||||
await alert_service.start()
|
||||
self.logger.info("Inventory alert service started")
|
||||
# Initialize alert service with EventPublisher
|
||||
if self.event_publisher:
|
||||
alert_service = InventoryAlertService(self.event_publisher)
|
||||
await alert_service.start()
|
||||
self.logger.info("Inventory alert service started")
|
||||
|
||||
# Store alert service in app state
|
||||
app.state.alert_service = alert_service
|
||||
# Store alert service in app state
|
||||
app.state.alert_service = alert_service
|
||||
else:
|
||||
self.logger.error("Event publisher not initialized, alert service unavailable")
|
||||
|
||||
# Initialize and start delivery event consumer
|
||||
self.delivery_consumer = DeliveryEventConsumer()
|
||||
@@ -179,6 +186,7 @@ service.setup_standard_endpoints()
|
||||
# Include new standardized routers
|
||||
# IMPORTANT: Register audit router FIRST to avoid route matching conflicts
|
||||
service.add_router(audit.router)
|
||||
service.add_router(batch.router)
|
||||
service.add_router(ingredients.router)
|
||||
service.add_router(stock_entries.router)
|
||||
service.add_router(transformations.router)
|
||||
|
||||
Reference in New Issue
Block a user