This commit is contained in:
2026-02-03 02:53:46 +02:00
parent 57106df5ae
commit f46bf16428
5 changed files with 1243 additions and 35 deletions

View File

@@ -180,6 +180,15 @@ async def _run_calculation(ws: WebSocket, calc_id: str, data: dict):
poller_task = asyncio.create_task(progress_poller())
# Dynamic timeout based on radius
radius_m = settings.radius
if radius_m > 30_000:
calc_timeout = 600.0 # 10 min for 30-50km
elif radius_m > 10_000:
calc_timeout = 480.0 # 8 min for 10-30km
else:
calc_timeout = 300.0 # 5 min for ≤10km
# Run calculation with timeout
start_time = time.time()
try:
@@ -190,7 +199,7 @@ async def _run_calculation(ws: WebSocket, calc_id: str, data: dict):
progress_fn=sync_progress_fn,
tile_callback=_tile_callback,
),
timeout=300.0,
timeout=calc_timeout,
)
else:
points = await asyncio.wait_for(
@@ -199,7 +208,7 @@ async def _run_calculation(ws: WebSocket, calc_id: str, data: dict):
progress_fn=sync_progress_fn,
tile_callback=_tile_callback,
),
timeout=300.0,
timeout=calc_timeout,
)
except asyncio.TimeoutError:
cancel_token.cancel()
@@ -207,7 +216,8 @@ async def _run_calculation(ws: WebSocket, calc_id: str, data: dict):
await poller_task
from app.services.parallel_coverage_service import _kill_worker_processes
_kill_worker_processes()
await ws_manager.send_error(ws, calc_id, "Calculation timeout (5 min)")
timeout_min = int(calc_timeout / 60)
await ws_manager.send_error(ws, calc_id, f"Calculation timeout ({timeout_min} min)")
return
except asyncio.CancelledError:
cancel_token.cancel()