From 698cd6af80e2e6e50011f5bbb4037789c2c76960 Mon Sep 17 00:00:00 2001 From: Stream Date: Mon, 4 May 2026 14:30:01 +0300 Subject: [PATCH] auto-sync: 2026-05-04 14:30:01 --- tasks/enduro-trails/prototype/app.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tasks/enduro-trails/prototype/app.py b/tasks/enduro-trails/prototype/app.py index 61d69a1..c1d1f2b 100644 --- a/tasks/enduro-trails/prototype/app.py +++ b/tasks/enduro-trails/prototype/app.py @@ -502,32 +502,48 @@ async def post_route(req: RouteRequest): raise HTTPException(503, f"OSRM недоступен: {e}") # OSRM возвращает TooBig когда маршрут слишком длинный для N альтернатив + # Retry-цепочка: alternatives=5 → 3 → 1, ВСЕГДА с radiuses (snap radius критичен для длинных маршрутов) if data.get("code") == "TooBig": - # Пробуем с меньшим числом альтернатив url_retry3 = ( f"{OSRM_URL}/route/v1/driving/{coords_str}" f"?alternatives=3&overview=full&geometries=geojson&annotations=false" + f"&radiuses={radiuses_str}" ) try: - async with httpx.AsyncClient(timeout=30) as client: + async with httpx.AsyncClient(timeout=60) as client: resp = await client.get(url_retry3) data = resp.json() except Exception as e: raise HTTPException(503, f"OSRM недоступен: {e}") if data.get("code") == "TooBig": - # Всё ещё TooBig — пробуем совсем без альтернатив url_retry1 = ( f"{OSRM_URL}/route/v1/driving/{coords_str}" f"?overview=full&geometries=geojson&alternatives=false" + f"&radiuses={radiuses_str}" ) try: - async with httpx.AsyncClient(timeout=30) as client: + async with httpx.AsyncClient(timeout=60) as client: resp = await client.get(url_retry1) data = resp.json() except Exception as e: raise HTTPException(503, f"OSRM недоступен: {e}") + # Если NoSegment — пробуем с увеличенным radius (10 км вместо 5) + if data.get("code") == "NoSegment": + radiuses_wide = ";".join(["10000"] * len(req.waypoints)) + url_wide = ( + f"{OSRM_URL}/route/v1/driving/{coords_str}" + f"?overview=full&geometries=geojson&alternatives=false" + f"&radiuses={radiuses_wide}" + ) + try: + async with httpx.AsyncClient(timeout=60) as client: + resp = await client.get(url_wide) + data = resp.json() + except Exception as e: + raise HTTPException(503, f"OSRM недоступен: {e}") + if data.get("code") != "Ok" or not data.get("routes"): osrm_code = data.get("code", "Unknown") osrm_msg = data.get("message", "")