Add frontend procurement implementation 2

This commit is contained in:
Urtzi Alfaro
2025-09-09 17:40:57 +02:00
parent a290663ec5
commit 23e088dcb4
6 changed files with 339 additions and 75 deletions

View File

@@ -15,6 +15,7 @@ from app.core.config import settings
from app.core.database import init_database, get_db_health
from app.api.orders import router as orders_router
from app.api.procurement import router as procurement_router
from app.services.procurement_scheduler_service import ProcurementSchedulerService
# Configure logging
logger = structlog.get_logger()
@@ -26,6 +27,16 @@ async def lifespan(app: FastAPI):
# Startup
try:
await init_database()
logger.info("Database initialized successfully")
# Initialize procurement scheduler service
scheduler_service = ProcurementSchedulerService(settings)
await scheduler_service.start()
logger.info("Procurement scheduler service started")
# Store scheduler service in app state
app.state.scheduler_service = scheduler_service
logger.info("Orders service started successfully")
except Exception as e:
logger.error("Failed to initialize orders service", error=str(e))
@@ -35,6 +46,13 @@ async def lifespan(app: FastAPI):
# Shutdown
logger.info("Orders service shutting down")
try:
# Stop scheduler service
if hasattr(app.state, 'scheduler_service'):
await app.state.scheduler_service.stop()
logger.info("Scheduler service stopped")
except Exception as e:
logger.error("Error stopping scheduler service", error=str(e))
# Create FastAPI application
@@ -98,6 +116,21 @@ async def root():
}
@app.post("/test/procurement-scheduler")
async def test_procurement_scheduler():
"""Test endpoint to manually trigger procurement scheduler"""
try:
if hasattr(app.state, 'scheduler_service'):
scheduler_service = app.state.scheduler_service
await scheduler_service.test_procurement_generation()
return {"message": "Procurement scheduler test triggered successfully"}
else:
return {"error": "Scheduler service not available"}
except Exception as e:
logger.error("Error testing procurement scheduler", error=str(e))
return {"error": f"Failed to trigger scheduler test: {str(e)}"}
@app.middleware("http")
async def logging_middleware(request: Request, call_next):
"""Add request logging middleware"""