Spaces:
Paused

dushyantsingh0 commited on
Commit
ca9ebef
·
1 Parent(s): 6150554

backend stabilization

Browse files
Files changed (1) hide show
  1. api/v1/dashboard.py +36 -13
api/v1/dashboard.py CHANGED
@@ -113,24 +113,47 @@ async def get_dashboard_hydration(
113
  return None
114
 
115
 
116
- # return_exceptions=False (default) is fine here because we catch them inside the helpers
117
- stats, reports, queue, escalations, insights = await asyncio.gather(
118
- run_stats(),
119
- run_reports(),
120
- run_queue(),
121
- run_escalations(),
122
- run_insights()
123
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  return {
126
- "stats": stats,
127
- "reports": reports,
128
- "queue": queue,
129
- "escalations": escalations,
130
- "insights": insights,
131
  "workspace_id": stats.get("workspace_id") if isinstance(stats, dict) else None
132
  }
133
 
 
134
  @router.get("/stats/")
135
  async def get_dashboard_stats(
136
  request: Request = None,
 
113
  return None
114
 
115
 
116
+ # Unified Hydration with strict 35s total timeout to prevent frontend 45s timeout
117
+ try:
118
+ stats, reports, queue, escalations, insights = await asyncio.wait_for(
119
+ asyncio.gather(
120
+ run_stats(),
121
+ run_reports(),
122
+ run_queue(),
123
+ run_escalations(),
124
+ run_insights(),
125
+ return_exceptions=True # Prevent one failure from killing the entire hydration
126
+ ),
127
+ timeout=35.0
128
+ )
129
+ except asyncio.TimeoutError:
130
+ logger.error(f"Dashboard Hydration CRITICAL TIMEOUT for workspace {workspace_id}")
131
+ return {
132
+ "stats": {"by_status": {}, "performance": {}, "workspace_id": workspace_id},
133
+ "reports": {"daily": [], "volume": {}, "csat": {}, "sla": {}},
134
+ "queue": [],
135
+ "escalations": {"rules": [], "breaches": [], "audit": []},
136
+ "insights": None,
137
+ "error": "HYDRATION_TIMEOUT"
138
+ }
139
+
140
+ # Handle exceptions in gathered tasks
141
+ def handle_task_res(res, fallback):
142
+ if isinstance(res, Exception):
143
+ logger.error(f"Hydration Component Task Failed: {res}")
144
+ return fallback
145
+ return res
146
 
147
  return {
148
+ "stats": handle_task_res(stats, {"by_status": {}, "performance": {}, "workspace_id": workspace_id}),
149
+ "reports": handle_task_res(reports, {"daily": [], "volume": {}, "csat": {}, "sla": {}}),
150
+ "queue": handle_task_res(queue, []),
151
+ "escalations": handle_task_res(escalations, {"rules": [], "breaches": [], "audit": []}),
152
+ "insights": handle_task_res(insights, None),
153
  "workspace_id": stats.get("workspace_id") if isinstance(stats, dict) else None
154
  }
155
 
156
+
157
  @router.get("/stats/")
158
  async def get_dashboard_stats(
159
  request: Request = None,