Fix POI distance calculation: OSRM index separator and error handling

- Fix OSRM client to use semicolons (not commas) for source/destination
  indices in /table API requests. Commas caused "Query string malformed"
  errors for any batch with more than one origin.
- Add error handling in poi_distance_calculator for unreachable routing
  engines (OSRM/OTP). Connection failures now log an error and skip the
  mode instead of crashing the entire Celery task.
This commit is contained in:
Viktor Barzin 2026-02-08 14:50:09 +00:00
parent 7084c46f89
commit 8a5d1b3787
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 25 additions and 16 deletions

View file

@ -47,8 +47,8 @@ async def osrm_table(
coords_str = ";".join(f"{lng},{lat}" for lng, lat in all_coords) coords_str = ";".join(f"{lng},{lat}" for lng, lat in all_coords)
# Source/destination indices # Source/destination indices
source_indices = ",".join(str(i) for i in range(len(origins))) source_indices = ";".join(str(i) for i in range(len(origins)))
dest_indices = ",".join(str(i) for i in range(len(origins), len(all_coords))) dest_indices = ";".join(str(i) for i in range(len(origins), len(all_coords)))
url = ( url = (
f"{base_url}/table/v1/{profile}/{coords_str}" f"{base_url}/table/v1/{profile}/{coords_str}"

View file

@ -88,20 +88,29 @@ async def calculate_poi_distances(
f"(skipped {len(existing)} already computed)" f"(skipped {len(existing)} already computed)"
) )
if mode_upper in _OSRM_PROFILES: try:
computed = await _compute_osrm( if mode_upper in _OSRM_PROFILES:
pending_listings, poi, mode_upper, listing_type, computed = await _compute_osrm(
config, poi_repo, on_progress, pending_listings, poi, mode_upper, listing_type,
total_computed, len(listings) * total_modes, config, poi_repo, on_progress,
) total_computed, len(listings) * total_modes,
elif mode_upper == "TRANSIT": )
computed = await _compute_transit( elif mode_upper == "TRANSIT":
pending_listings, poi, listing_type, computed = await _compute_transit(
config, poi_repo, on_progress, pending_listings, poi, listing_type,
total_computed, len(listings) * total_modes, config, poi_repo, on_progress,
) total_computed, len(listings) * total_modes,
else: )
logger.warning(f"Unknown travel mode: {mode_upper}") else:
logger.warning(f"Unknown travel mode: {mode_upper}")
continue
except (aiohttp.ClientError, OSError) as e:
logger.error(f"Routing engine unreachable for {mode_upper}: {e}")
if on_progress:
on_progress(
total_computed, len(listings) * total_modes,
f"{mode_upper}: routing engine unavailable"
)
continue continue
total_computed += computed total_computed += computed