Fix critical bugs and standardize service integrations

Critical Fixes:
- Orchestrator: Add missing OrchestrationStatus import (fixes HTTP 500 during demo clone)
- Procurement: Migrate from custom cache utils to shared Redis utils
- Suppliers: Use proper Settings for Redis configuration with TLS/auth
- Recipes/Suppliers clients: Fix endpoint paths (remove duplicate path segments)
- Procurement client: Use suppliers service directly for supplier details

Details:
1. services/orchestrator/app/api/internal_demo.py:
   - Added OrchestrationStatus import to fix cloning error
   - This was causing HTTP 500 errors during demo session cloning

2. services/procurement/app/api/purchase_orders.py + service:
   - Replaced app.utils.cache with shared.redis_utils
   - Standardizes caching across all services
   - Removed custom cache utilities (deleted app/utils/cache.py)

3. services/suppliers/app/consumers/alert_event_consumer.py:
   - Use Settings().REDIS_URL instead of os.getenv
   - Ensures proper Redis connection with TLS and authentication

4. shared/clients/recipes_client.py:
   - Fixed endpoint paths: recipes/recipes/{id} → recipes/{id}
   - Applied to all recipe methods (by_id, by_products, instructions, yield)

5. shared/clients/suppliers_client.py:
   - Fixed endpoint path: suppliers/suppliers/{id} → suppliers/{id}

6. shared/clients/procurement_client.py:
   - get_supplier_by_id now uses SuppliersServiceClient directly
   - Removes incorrect call to procurement service for supplier details

Impact:
- Demo session cloning now works without orchestrator errors 
- Consistent Redis usage across all services
- Correct service boundaries (suppliers data from suppliers service)
- Clean client endpoint paths

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Urtzi Alfaro
2025-12-16 11:33:22 +01:00
parent 9f3b39bd28
commit c68d82ca7f
9 changed files with 48 additions and 319 deletions

View File

@@ -27,7 +27,7 @@ from app.schemas.purchase_order_schemas import (
)
from shared.routing import RouteBuilder
from shared.auth.decorators import get_current_user_dep
from app.utils.cache import get_cached, set_cached, make_cache_key
from shared.redis_utils import get_value, set_with_ttl
import structlog
logger = structlog.get_logger()
@@ -146,17 +146,14 @@ async def list_purchase_orders(
# Only skip cache for supplier_id filter and pagination (skip > 0)
cache_key = None
if skip == 0 and supplier_id is None:
cache_key = make_cache_key(
"purchase_orders",
tenant_id,
limit=limit,
status=status, # Include status in cache key
enrich_supplier=enrich_supplier
)
cached_result = await get_cached(cache_key)
if cached_result is not None:
logger.debug("Cache hit for purchase orders", cache_key=cache_key, tenant_id=tenant_id, status=status)
return [PurchaseOrderResponse(**po) for po in cached_result]
cache_key = f"purchase_orders:{tenant_id}:limit:{limit}:status:{status}:enrich:{enrich_supplier}"
try:
cached_result = await get_value(cache_key)
if cached_result is not None:
logger.debug("Cache hit for purchase orders", cache_key=cache_key, tenant_id=tenant_id, status=status)
return [PurchaseOrderResponse(**po) for po in cached_result]
except Exception as e:
logger.warning("Cache read failed, continuing without cache", cache_key=cache_key, error=str(e))
# Cache miss - fetch from database
pos = await service.list_purchase_orders(
@@ -172,8 +169,12 @@ async def list_purchase_orders(
# PERFORMANCE OPTIMIZATION: Cache the result (20s TTL for purchase orders)
if cache_key:
await set_cached(cache_key, [po.model_dump() for po in result], ttl=20)
logger.debug("Cached purchase orders", cache_key=cache_key, ttl=20, tenant_id=tenant_id, status=status)
try:
import json
await set_with_ttl(cache_key, json.dumps([po.model_dump() for po in result]), ttl=20)
logger.debug("Cached purchase orders", cache_key=cache_key, ttl=20, tenant_id=tenant_id, status=status)
except Exception as e:
logger.warning("Cache write failed, continuing without caching", cache_key=cache_key, error=str(e))
return result