@mytec: 3.5.0 cont
This commit is contained in:
@@ -69,8 +69,16 @@ async def calculate_coverage(request: CoverageRequest) -> CoverageResponse:
|
||||
start_time = time.time()
|
||||
cancel_token = CancellationToken()
|
||||
|
||||
# Dynamic timeout based on radius (large radius needs more time for tiled processing)
|
||||
radius_m = request.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
|
||||
|
||||
try:
|
||||
# Calculate with 5-minute timeout
|
||||
if len(request.sites) == 1:
|
||||
points = await asyncio.wait_for(
|
||||
coverage_service.calculate_coverage(
|
||||
@@ -78,7 +86,7 @@ async def calculate_coverage(request: CoverageRequest) -> CoverageResponse:
|
||||
request.settings,
|
||||
cancel_token,
|
||||
),
|
||||
timeout=300.0
|
||||
timeout=calc_timeout,
|
||||
)
|
||||
else:
|
||||
points = await asyncio.wait_for(
|
||||
@@ -87,14 +95,15 @@ async def calculate_coverage(request: CoverageRequest) -> CoverageResponse:
|
||||
request.settings,
|
||||
cancel_token,
|
||||
),
|
||||
timeout=300.0
|
||||
timeout=calc_timeout,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
cancel_token.cancel()
|
||||
# Force cleanup orphaned worker processes
|
||||
from app.services.parallel_coverage_service import _kill_worker_processes
|
||||
killed = _kill_worker_processes()
|
||||
detail = f"Calculation timeout (5 min). Cleaned up {killed} workers." if killed else "Calculation timeout (5 min) — try smaller radius or lower resolution"
|
||||
timeout_min = int(calc_timeout / 60)
|
||||
detail = f"Calculation timeout ({timeout_min} min). Cleaned up {killed} workers." if killed else f"Calculation timeout ({timeout_min} min) — try smaller radius or lower resolution"
|
||||
raise HTTPException(408, detail)
|
||||
except asyncio.CancelledError:
|
||||
cancel_token.cancel()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user