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

99
shared/clients/inventory_client.py Normal file → Executable file
View File

@@ -759,6 +759,105 @@ class InventoryServiceClient(BaseServiceClient):
logger.error("Inventory service health check failed", error=str(e))
return False
async def trigger_inventory_alerts_internal(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Trigger inventory alerts for a tenant (internal service use only).
This method calls the internal endpoint which is protected by X-Internal-Service header.
The endpoint should trigger alerts specifically for the given tenant.
Args:
tenant_id: Tenant ID to trigger alerts for
Returns:
Dict with trigger results or None if failed
"""
try:
# Call internal endpoint via gateway using tenant-scoped URL pattern
# Endpoint: /api/v1/tenants/{tenant_id}/inventory/internal/alerts/trigger
result = await self._make_request(
method="POST",
endpoint="inventory/internal/alerts/trigger",
tenant_id=tenant_id,
data={},
headers={"X-Internal-Service": "demo-session"}
)
if result:
logger.info(
"Inventory alerts triggered successfully via internal endpoint",
tenant_id=tenant_id,
alerts_generated=result.get("alerts_generated", 0)
)
else:
logger.warning(
"Inventory alerts internal endpoint returned no result",
tenant_id=tenant_id
)
return result
except Exception as e:
logger.error(
"Error triggering inventory alerts via internal endpoint",
tenant_id=tenant_id,
error=str(e)
)
return None
# ================================================================
# INTERNAL AI INSIGHTS METHODS
# ================================================================
async def trigger_safety_stock_insights_internal(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Trigger safety stock optimization insights for a tenant (internal service use only).
This method calls the internal endpoint which is protected by X-Internal-Service header.
Args:
tenant_id: Tenant ID to trigger insights for
Returns:
Dict with trigger results or None if failed
"""
try:
result = await self._make_request(
method="POST",
endpoint="inventory/internal/ml/generate-safety-stock-insights",
tenant_id=tenant_id,
data={"tenant_id": tenant_id},
headers={"X-Internal-Service": "demo-session"}
)
if result:
logger.info(
"Safety stock insights triggered successfully via internal endpoint",
tenant_id=tenant_id,
insights_posted=result.get("insights_posted", 0)
)
else:
logger.warning(
"Safety stock insights internal endpoint returned no result",
tenant_id=tenant_id
)
return result
except Exception as e:
logger.error(
"Error triggering safety stock insights via internal endpoint",
tenant_id=tenant_id,
error=str(e)
)
return None
# Factory function for dependency injection
def create_inventory_client(config: BaseServiceSettings) -> InventoryServiceClient: