Fix POI distance calculation reliability for remote/Celery execution
- Fix silent log loss: replace hardcoded "uvicorn.error" logger with __name__ in osrm_client, otp_client, poi_distance_calculator, and poi_tasks (uvicorn logger has no handlers in Celery worker, so all errors were silently dropped) - Add Celery retry: autoretry_for=(Exception,), max_retries=3, retry_backoff - Add top-level exception handling in task with full traceback logging - Fix upsert_distances: replace session.merge() (PK-based) with proper dialect-aware INSERT ON DUPLICATE KEY UPDATE / ON CONFLICT DO UPDATE - Filter out listings with null/zero coordinates before routing - Raise OSError when all routing engines fail with 0 results computed, distinguishing "nothing to compute" from "all engines unreachable"
This commit is contained in:
parent
46995cb9da
commit
5b566bab4c
5 changed files with 85 additions and 16 deletions
|
|
@ -11,7 +11,7 @@ from repositories.listing_repository import ListingRepository
|
|||
from repositories.poi_repository import POIRepository
|
||||
from services.poi_distance_calculator import calculate_poi_distances
|
||||
|
||||
logger = logging.getLogger("uvicorn.error")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
celery_logger = logging.getLogger("celery.task")
|
||||
if not celery_logger.handlers:
|
||||
|
|
@ -23,7 +23,13 @@ if not celery_logger.handlers:
|
|||
celery_logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
@app.task(
|
||||
bind=True,
|
||||
autoretry_for=(Exception,),
|
||||
max_retries=3,
|
||||
retry_backoff=True,
|
||||
retry_backoff_max=300,
|
||||
)
|
||||
def calculate_poi_distances_task(
|
||||
self: Task,
|
||||
poi_id: int,
|
||||
|
|
@ -70,17 +76,23 @@ def calculate_poi_distances_task(
|
|||
"message": message,
|
||||
})
|
||||
|
||||
total = asyncio.run(
|
||||
calculate_poi_distances(
|
||||
listing_repo=listing_repo,
|
||||
poi_repo=poi_repo,
|
||||
poi=poi,
|
||||
travel_modes=travel_modes,
|
||||
listing_type=lt,
|
||||
listing_ids=listing_ids,
|
||||
on_progress=on_progress,
|
||||
try:
|
||||
total = asyncio.run(
|
||||
calculate_poi_distances(
|
||||
listing_repo=listing_repo,
|
||||
poi_repo=poi_repo,
|
||||
poi=poi,
|
||||
travel_modes=travel_modes,
|
||||
listing_type=lt,
|
||||
listing_ids=listing_ids,
|
||||
on_progress=on_progress,
|
||||
)
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
celery_logger.exception(
|
||||
f"POI distance calculation failed: poi_id={poi_id}"
|
||||
)
|
||||
raise # Let Celery's autoretry handle it
|
||||
|
||||
celery_logger.info(f"POI distance calculation complete: {total} distances computed")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue