demo seed change

This commit is contained in:
Urtzi Alfaro
2025-12-13 23:57:54 +01:00
parent f3688dfb04
commit ff830a3415
299 changed files with 20328 additions and 19485 deletions

View File

@@ -11,12 +11,14 @@ from sqlalchemy import text
from app.core.config import settings
from app.core.database import database_manager
from app.services.inventory_alert_service import InventoryAlertService
from app.services.inventory_scheduler import InventoryScheduler
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 (
internal_demo,
batch,
ingredients,
stock_entries,
@@ -29,10 +31,11 @@ from app.api import (
dashboard,
analytics,
sustainability,
internal_demo,
audit,
ml_insights
)
from app.api.internal_alert_trigger import router as internal_alert_trigger_router
from app.api.internal_demo import router as internal_demo_router
class InventoryService(StandardFastAPIService):
@@ -115,8 +118,14 @@ class InventoryService(StandardFastAPIService):
await alert_service.start()
self.logger.info("Inventory alert service started")
# Store alert service in app state
# Initialize inventory scheduler with alert service and database manager
inventory_scheduler = InventoryScheduler(alert_service, self.database_manager)
await inventory_scheduler.start()
self.logger.info("Inventory scheduler started")
# Store services in app state
app.state.alert_service = alert_service
app.state.inventory_scheduler = inventory_scheduler # Store scheduler for manual triggering
else:
self.logger.error("Event publisher not initialized, alert service unavailable")
@@ -136,6 +145,11 @@ class InventoryService(StandardFastAPIService):
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for inventory service"""
# Stop inventory scheduler
if hasattr(app.state, 'inventory_scheduler') and app.state.inventory_scheduler:
await app.state.inventory_scheduler.stop()
self.logger.info("Inventory scheduler stopped")
# Cancel delivery consumer task
if self.delivery_consumer_task and not self.delivery_consumer_task.done():
self.delivery_consumer_task.cancel()
@@ -198,8 +212,10 @@ service.add_router(food_safety_operations.router)
service.add_router(dashboard.router)
service.add_router(analytics.router)
service.add_router(sustainability.router)
service.add_router(internal_demo.router)
service.add_router(internal_demo.router, tags=["internal-demo"])
service.add_router(ml_insights.router) # ML insights endpoint
service.add_router(ml_insights.internal_router) # Internal ML insights endpoint for demo cloning
service.add_router(internal_alert_trigger_router) # Internal alert trigger for demo cloning
if __name__ == "__main__":
@@ -211,4 +227,4 @@ if __name__ == "__main__":
port=8000,
reload=os.getenv("RELOAD", "false").lower() == "true",
log_level="info"
)
)