Add user delete process
This commit is contained in:
@@ -43,6 +43,24 @@ class OrchestratorTestResponse(BaseModel):
|
||||
summary: dict = {}
|
||||
|
||||
|
||||
class OrchestratorWorkflowRequest(BaseModel):
|
||||
"""Request schema for daily workflow trigger"""
|
||||
dry_run: bool = Field(False, description="Dry run mode (no actual changes)")
|
||||
|
||||
|
||||
class OrchestratorWorkflowResponse(BaseModel):
|
||||
"""Response schema for daily workflow trigger"""
|
||||
success: bool
|
||||
message: str
|
||||
tenant_id: str
|
||||
run_id: Optional[str] = None
|
||||
forecasting_completed: bool = False
|
||||
production_completed: bool = False
|
||||
procurement_completed: bool = False
|
||||
notifications_sent: bool = False
|
||||
summary: dict = {}
|
||||
|
||||
|
||||
# ================================================================
|
||||
# API ENDPOINTS
|
||||
# ================================================================
|
||||
@@ -128,6 +146,97 @@ async def trigger_orchestrator_test(
|
||||
raise HTTPException(status_code=500, detail=f"Orchestrator test failed: {str(e)}")
|
||||
|
||||
|
||||
@router.post("/run-daily-workflow", response_model=OrchestratorWorkflowResponse)
|
||||
async def run_daily_workflow(
|
||||
tenant_id: str,
|
||||
request_data: Optional[OrchestratorWorkflowRequest] = None,
|
||||
request: Request = None,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Trigger the daily orchestrated workflow for a tenant
|
||||
|
||||
This endpoint runs the complete daily workflow which includes:
|
||||
1. Forecasting Service: Generate demand forecasts
|
||||
2. Production Service: Create production schedule from forecasts
|
||||
3. Procurement Service: Generate procurement plan
|
||||
4. Notification Service: Send relevant notifications
|
||||
|
||||
This is the production endpoint used by the dashboard scheduler button.
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant ID to orchestrate
|
||||
request_data: Optional request data with dry_run flag
|
||||
request: FastAPI request object
|
||||
db: Database session
|
||||
|
||||
Returns:
|
||||
OrchestratorWorkflowResponse with workflow execution results
|
||||
"""
|
||||
logger.info("Daily workflow trigger requested", tenant_id=tenant_id)
|
||||
|
||||
# Handle optional request_data
|
||||
if request_data is None:
|
||||
request_data = OrchestratorWorkflowRequest()
|
||||
|
||||
try:
|
||||
# Get scheduler service from app state
|
||||
if not hasattr(request.app.state, 'scheduler_service'):
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="Orchestrator scheduler service not available"
|
||||
)
|
||||
|
||||
scheduler_service = request.app.state.scheduler_service
|
||||
|
||||
# Trigger orchestration (use full workflow, not test scenario)
|
||||
tenant_uuid = uuid.UUID(tenant_id)
|
||||
result = await scheduler_service.trigger_orchestration_for_tenant(
|
||||
tenant_id=tenant_uuid,
|
||||
test_scenario=None # Full production workflow
|
||||
)
|
||||
|
||||
# Get the latest run for this tenant
|
||||
repo = OrchestrationRunRepository(db)
|
||||
latest_run = await repo.get_latest_run_for_tenant(tenant_uuid)
|
||||
|
||||
# Build response
|
||||
response = OrchestratorWorkflowResponse(
|
||||
success=result.get('success', False),
|
||||
message=result.get('message', 'Daily workflow completed successfully'),
|
||||
tenant_id=tenant_id,
|
||||
run_id=str(latest_run.id) if latest_run else None,
|
||||
forecasting_completed=latest_run.forecasting_status == 'success' if latest_run else False,
|
||||
production_completed=latest_run.production_status == 'success' if latest_run else False,
|
||||
procurement_completed=latest_run.procurement_status == 'success' if latest_run else False,
|
||||
notifications_sent=latest_run.notification_status == 'success' if latest_run else False,
|
||||
summary={
|
||||
'run_number': latest_run.run_number if latest_run else 0,
|
||||
'forecasts_generated': latest_run.forecasts_generated if latest_run else 0,
|
||||
'production_batches_created': latest_run.production_batches_created if latest_run else 0,
|
||||
'purchase_orders_created': latest_run.purchase_orders_created if latest_run else 0,
|
||||
'notifications_sent': latest_run.notifications_sent if latest_run else 0,
|
||||
'duration_seconds': latest_run.duration_seconds if latest_run else 0
|
||||
}
|
||||
)
|
||||
|
||||
logger.info("Daily workflow completed",
|
||||
tenant_id=tenant_id,
|
||||
success=response.success,
|
||||
run_id=response.run_id)
|
||||
|
||||
return response
|
||||
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=f"Invalid tenant ID: {str(e)}")
|
||||
except Exception as e:
|
||||
logger.error("Daily workflow failed",
|
||||
tenant_id=tenant_id,
|
||||
error=str(e),
|
||||
exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=f"Daily workflow failed: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def orchestrator_health():
|
||||
"""Check orchestrator health"""
|
||||
|
||||
Reference in New Issue
Block a user