sync: capture the production server's code, which was never committed

/root/Routes-api on 31.97.228.132 is not a git repository. Work had been
done directly on the box and existed nowhere else -- a single rm -rf from
being lost, and impossible to review or roll back.

Deploying the previous HEAD over it would have silently reverted all of
this. Most visibly the Valhalla road-backend probe in main.py, whose own
comment explains why it exists: road sequencing degrades to aerial
silently by design, so an unreachable backend stays invisible, "which is
exactly how the expired Google key went unnoticed". Overwriting it would
have reintroduced precisely the failure it was written to catch, and the
service would have kept answering 200 throughout.

The server had also moved from Google Maps to Valhalla for road distance
(VALHALLA_URL, road_backend_status, +190 lines in route_optimizer),
extended docker-compose from 44 to 95 lines, and changed rider fetching,
health, dynamic config and the cache layer.

Only 10 files differ in substance. The other 27 that appeared to differ
were CRLF-vs-LF noise -- the server writes CRLF -- and are normalised to
LF here rather than committed as spurious whole-file rewrites.

Committed as-is, before any change of mine, so the diff that follows is
reviewable against what is actually running.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Suriya
2026-08-11 15:56:32 +05:30
parent f804791864
commit 9ef2f61870
10 changed files with 327 additions and 75 deletions

View File

@@ -6,7 +6,7 @@ import sys
import time
from contextlib import asynccontextmanager
# Load .env (DB_*, REDIS_*, GOOGLE_MAPS_API_KEY) into the environment early,
# Load .env (DB_*, REDIS_*, VALHALLA_URL) into the environment early,
# before any service reads os.getenv at import time.
try:
from dotenv import load_dotenv
@@ -28,7 +28,7 @@ from app.core.exception_handlers import (
)
from app.core.exceptions import APIException
from app.middleware.request_id import RequestIDMiddleware
from app.routes import cache_router, health_router, ml_router, ml_web_router, optimization_router, batch_analytics_router, riders_router, doormile_router
from app.routes import cache_router, health_router, ml_router, ml_web_router, optimization_router, batch_analytics_router, riders_router
# ---------------------------------------------------------------------------
# Logging
@@ -111,6 +111,27 @@ async def lifespan(app: FastAPI):
except Exception as e:
logger.warning(f"[RoadAgent] Decision agent start failed (non-fatal): {e}")
# Probe the Valhalla matrix backend once. Road sequencing degrades to aerial
# silently by design, so without this an unreachable or still-building backend
# stays invisible — which is exactly how the expired Google key went unnoticed.
try:
from app.services.routing.route_optimizer import road_backend_status
_rb = await road_backend_status()
if not _rb.get("configured"):
logger.warning("[RoadMatrix] VALHALLA_URL not set - aerial sequencing only.")
elif _rb.get("reachable"):
logger.info(
f"[RoadMatrix] Valhalla ready at {_rb.get('url')} "
f"(version={_rb.get('version')}, tiles={_rb.get('tileset_last_modified')})"
)
else:
logger.warning(
f"[RoadMatrix] Valhalla at {_rb.get('url')} unreachable "
f"({_rb.get('detail')}) - aerial fallback until it answers."
)
except Exception as e:
logger.warning(f"[RoadMatrix] Backend probe failed (non-fatal): {e}")
logger.info("[OK] Application ready.")
yield
logger.info("[STOP] Route Optimization API shutting down.")
@@ -162,7 +183,6 @@ app.include_router(ml_router)
app.include_router(ml_web_router)
app.include_router(batch_analytics_router)
app.include_router(riders_router)
app.include_router(doormile_router)
@app.get("/", tags=["Root"])