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

@@ -2,6 +2,9 @@
"""
Internal API for triggering production alerts.
Used by demo session cloning to generate realistic production delay alerts.
URL Pattern: /api/v1/tenants/{tenant_id}/production/internal/alerts/trigger
This follows the tenant-scoped pattern so gateway can proxy correctly.
"""
from fastapi import APIRouter, HTTPException, Request, Path
@@ -13,16 +16,20 @@ logger = structlog.get_logger()
router = APIRouter()
@router.post("/api/internal/production-alerts/trigger/{tenant_id}")
# New URL pattern: tenant-scoped so gateway proxies to production service correctly
@router.post("/api/v1/tenants/{tenant_id}/production/internal/alerts/trigger")
async def trigger_production_alerts(
tenant_id: UUID = Path(..., description="Tenant ID to check production for"),
request: Request = None
) -> dict:
"""
Trigger production alert checks for a specific tenant (internal use only).
Trigger comprehensive production alert checks for a specific tenant (internal use only).
This endpoint is called by the demo session cloning process after production
batches are seeded to generate realistic production delay alerts.
batches are seeded to generate realistic production alerts including:
- Production delays
- Equipment maintenance alerts
- Batch start delays
Security: Protected by X-Internal-Service header check.
"""
@@ -35,40 +42,36 @@ async def trigger_production_alerts(
detail="This endpoint is for internal service use only"
)
# Get production alert service from app state
production_alert_service = getattr(request.app.state, 'production_alert_service', None)
# Get production scheduler from app state
production_scheduler = getattr(request.app.state, 'production_scheduler', None)
if not production_alert_service:
logger.error("Production alert service not initialized")
if not production_scheduler:
logger.error("Production scheduler not initialized")
raise HTTPException(
status_code=500,
detail="Production alert service not available"
detail="Production scheduler not available"
)
# Trigger production alert checks (checks all tenants, including this one)
logger.info("Triggering production alert checks", tenant_id=str(tenant_id))
await production_alert_service.check_production_delays()
# Trigger comprehensive production alert checks for the specific tenant
logger.info("Triggering comprehensive production alert checks", tenant_id=str(tenant_id))
# Return success (service checks all tenants, we can't get specific count)
result = {"total_alerts": 0, "message": "Production alert checks triggered"}
# Call the scheduler's manual trigger method
result = await production_scheduler.trigger_manual_check(tenant_id)
logger.info(
"Production alert checks completed",
tenant_id=str(tenant_id),
alerts_generated=result.get("total_alerts", 0)
)
if result.get("success", False):
logger.info(
"Production alert checks completed successfully",
tenant_id=str(tenant_id),
alerts_generated=result.get("alerts_generated", 0)
)
else:
logger.error(
"Production alert checks failed",
tenant_id=str(tenant_id),
error=result.get("error", "Unknown error")
)
return {
"success": True,
"tenant_id": str(tenant_id),
"alerts_generated": result.get("total_alerts", 0),
"breakdown": {
"critical": result.get("critical", 0),
"high": result.get("high", 0),
"medium": result.get("medium", 0),
"low": result.get("low", 0)
}
}
return result
except HTTPException:
raise