REFACTOR ALL APIs

This commit is contained in:
Urtzi Alfaro
2025-10-06 15:27:01 +02:00
parent dc8221bd2f
commit 38fb98bc27
166 changed files with 18454 additions and 13605 deletions

View File

@@ -291,7 +291,7 @@ async def websocket_training_progress(websocket: WebSocket, tenant_id: str, job_
# Build WebSocket URL to training service
training_service_base = settings.TRAINING_SERVICE_URL.rstrip('/')
training_ws_url = training_service_base.replace('http://', 'ws://').replace('https://', 'wss://')
training_ws_url = f"{training_ws_url}/api/v1/ws/tenants/{tenant_id}/training/jobs/{job_id}/live?token={token}"
training_ws_url = f"{training_ws_url}/api/v1/tenants/{tenant_id}/training/jobs/{job_id}/live?token={token}"
training_ws = None
heartbeat_task = None
@@ -348,12 +348,20 @@ async def websocket_training_progress(websocket: WebSocket, tenant_id: str, job_
try:
# Use longer timeout to avoid conflicts with frontend 30s heartbeat
# Frontend sends ping every 30s, so we need to allow for some latency
message = await asyncio.wait_for(websocket.receive_text(), timeout=45.0)
data = await asyncio.wait_for(websocket.receive(), timeout=45.0)
last_activity = asyncio.get_event_loop().time()
# Forward the message to training service
await training_ws.send(message)
logger.debug(f"Forwarded message to training service for job {job_id}: {message[:100]}...")
# Handle different message types
if data.get("type") == "websocket.receive":
if "text" in data:
message = data["text"]
# Forward text messages to training service
await training_ws.send(message)
logger.debug(f"Forwarded message to training service for job {job_id}: {message[:100]}...")
elif "bytes" in data:
# Forward binary messages if needed
await training_ws.send(data["bytes"])
# Ping/pong frames are automatically handled by Starlette/FastAPI
except asyncio.TimeoutError:
# No message received in 45 seconds, continue loop