Add forecasting demand insights trigger + fix RabbitMQ cleanup
Issue 1: Forecasting demand insights not triggered in demo workflow - Created internal ML endpoint: /forecasting/internal/ml/generate-demand-insights - Added trigger_demand_insights_internal() to ForecastServiceClient - Integrated forecasting insights into demo session post-clone workflow - Now triggers 4 AI insight types: price, safety stock, yield, + demand Issue 2: RabbitMQ client cleanup error in procurement service - Fixed: rabbitmq_client.close() → rabbitmq_client.disconnect() - Added proper cleanup in exception handler - Error: "'RabbitMQClient' object has no attribute 'close'" Files modified: - services/forecasting/app/api/ml_insights.py (new internal_router) - services/forecasting/app/main.py (register internal router) - shared/clients/forecast_client.py (new trigger method) - services/demo_session/app/services/clone_orchestrator.py (+ demand insights) - services/procurement/app/api/internal_demo.py (fix disconnect) Expected impact: - Demo sessions will now generate demand forecasting insights - No more RabbitMQ cleanup errors in logs - AI insights count should increase from 1 to 2-3 per session 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -968,6 +968,8 @@ class CloneOrchestrator:
|
||||
inventory_client = InventoryServiceClient(config, calling_service_name="demo-session")
|
||||
production_client = ProductionServiceClient(config, calling_service_name="demo-session")
|
||||
procurement_client = ProcurementServiceClient(config, service_name="demo-session")
|
||||
from shared.clients.forecast_client import ForecastServiceClient
|
||||
forecasting_client = ForecastServiceClient(config, calling_service_name="demo-session")
|
||||
|
||||
# For professional/enterprise demos, trigger all AI insights
|
||||
if demo_account_type in ["professional", "enterprise"]:
|
||||
@@ -1026,6 +1028,24 @@ class CloneOrchestrator:
|
||||
logger.error("Failed to trigger yield insights", tenant_id=virtual_tenant_id, error=str(e))
|
||||
results["yield_insights"] = {"error": str(e)}
|
||||
|
||||
# 4. Trigger demand forecasting insights
|
||||
try:
|
||||
logger.info("Triggering demand forecasting insights", tenant_id=virtual_tenant_id)
|
||||
result = await forecasting_client.trigger_demand_insights_internal(virtual_tenant_id)
|
||||
if result:
|
||||
results["demand_insights"] = result
|
||||
total_insights += result.get("insights_posted", 0)
|
||||
logger.info(
|
||||
"Demand insights generated",
|
||||
tenant_id=virtual_tenant_id,
|
||||
insights_posted=result.get("insights_posted", 0)
|
||||
)
|
||||
else:
|
||||
results["demand_insights"] = {"error": "No response from service"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to trigger demand insights", tenant_id=virtual_tenant_id, error=str(e))
|
||||
results["demand_insights"] = {"error": str(e)}
|
||||
|
||||
# Wait 2s for insights to be processed
|
||||
await asyncio.sleep(2.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user