Give TfL cycle lookups a single attempt

TfL can take over 15s to return 404 for destinations with no cycle route
(motorway services), and retrying that three times stalled a hotel for
almost a minute. The distance estimate covers the gap.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dphx7LL5JC8dAFYU7MMpoA
This commit is contained in:
2026-09-08 00:54:33 +01:00
co-authored by Claude Fable 5.1
parent 44c08850ed
commit e445892259
+6 -3
View File
@@ -457,7 +457,7 @@ def cycle_time(origin, hotel, when, app_key, deadline=None, journeys=None):
if not app_key: if not app_key:
return est_min, est_km, "estimate" return est_min, est_km, "estimate"
if journeys is None: if journeys is None:
journeys = tfl_journeys(origin, dest, when, CYCLE_QUERY, app_key, deadline=deadline) journeys = tfl_journeys(origin, dest, when, CYCLE_QUERY, app_key, retries=1, deadline=deadline)
for j in journeys: for j in journeys:
if isinstance(j.get("duration"), int): if isinstance(j.get("duration"), int):
km = sum((l.get("distance") or 0) for l in (j.get("legs") or [])) / 1000 km = sum((l.get("distance") or 0) for l in (j.get("legs") or [])) / 1000
@@ -577,11 +577,14 @@ def run_search(
ThreadPoolExecutor(max_workers=TFL_HOTEL_WORKERS) as hotel_pool: ThreadPoolExecutor(max_workers=TFL_HOTEL_WORKERS) as hotel_pool:
def price(h): def price(h):
# Kick off the cycle lookup first so it overlaps the fare lookups. # Kick off the cycle lookup first so it overlaps the fare lookups. One
# attempt only: TfL can take 15s+ to say there is no cycle route (e.g.
# motorway services), and the distance estimate is a fine fallback.
cycle_fut = None cycle_fut = None
if app_key: if app_key:
cycle_fut = tfl_pool.submit( cycle_fut = tfl_pool.submit(
tfl_journeys, origin, (h["lat"], h["lon"]), depart_dt, CYCLE_QUERY, app_key, deadline=deadline tfl_journeys, origin, (h["lat"], h["lon"]), depart_dt, CYCLE_QUERY, app_key,
retries=1, deadline=deadline,
) )
t = best_transport(origin, h, depart_dt, adults, railcard_holders, max_travel_min, app_key, t = best_transport(origin, h, depart_dt, adults, railcard_holders, max_travel_min, app_key,
deadline=deadline, pool=tfl_pool) deadline=deadline, pool=tfl_pool)