Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
7009ad4
1
Parent(s): 1d07780
fix: enforce fault-tolerant caching and resolve role-based 500 errors
Browse filesFiles changed (2)
- api/v1/reports.py+14-6
- api/v1/workspace.py+1-1
217 unmodified lines218219220221221222223224222223224225226227228229230231232233234230231235236237238239240241242217 unmodified lines redis = get_redis_client() cache_key = f"insights:narrative:{target_ws}" try: cached_val = await redis.get(cache_key) if cached_val: logger.info(f"⚡ Research Cache HIT [Narrative Insights]: {target_ws}") return json.loads(cached_val) cached_val = await redis.get(cache_key) if cached_val: logger.info(f"⚡ Research Cache HIT [Narrative Insights]: {target_ws}") return json.loads(cached_val) except Exception as e: logger.error(f"Redis cache lookup failed for insights: {str(e)}") # Continue to generate fresh insights if cache fails
# 3. Generate Narrative insight_text = await generate_service_insights(metrics, ticket_data) res_data = {"insights": insight_text, "generated_at": now.isoformat()} try: # Store with 15 minute TTL await redis.set(cache_key, json.dumps(res_data), ex=900) # Store with 15 minute TTL await redis.set(cache_key, json.dumps(res_data), ex=900) except Exception as e: logger.error(f"Redis cache storing failed for insights: {str(e)}")
return res_data
@router.get("/daily-stats/", dependencies=[Depends(require_roles(ALL_SC_ROLES + [UserRole.CUSTOMER_ADMIN]))])49 unmodified lines505152535354555649 unmodified lines return [ { **WorkspaceResponse.model_validate(row[0]).model_dump(), "role": row[1].value, "role": row[1].value if hasattr(row[1], 'value') else row[1], "is_primary": row[2] } for row in rows ]api/v1/reports.py+14-6
api/v1/workspace.py+1-1