Fix API base URL, rate-limit paging, background refresh; verify live against official API
- Base URL corrected to https://www.fuel-finder.service.gov.uk (the api.fuelfinder.service.gov.uk host in the portal's examples is stale — it does not resolve; www.fuel-finder... resolves to CloudFront and is what the live spec uses). Verified: /health now reports source=api, 8,010 stations, 0 failures. - Fuel Finder is strictly sequential (30 rpm per client, 429 on overlap): added FUEL_API_BATCH_SLEEP (default 4.0s) between pages ≈ 15 rpm. - Stale-cache refresh moved off the request path into a background thread — a multi-minute rate-limited sync no longer blows the app's 5s timeout; stale data is served while it catches up. - Multiple diesel variants (B7_STANDARD, B7_PREMIUM, B10) now map to DIESEL as the MINIMUM price, so a premium price can't inflate the cheapest-diesel reference (CSV relay took first-wins; min is safer). - Added B7_PREMIUM (underscore) to the fuel map — official key. - scripts/run.sh now prefers the project venv (bare python3 missed uvicorn when run outside an activated env). - Tests updated for min-diesel + B7_PREMIUM; 12/12 pass.
This commit is contained in:
@@ -26,16 +26,21 @@ FuelBoard app / widget
|
||||
- Token refreshed automatically before expiry (60s buffer); reused across the
|
||||
two batched loops (docs: reuse tokens until near expiry).
|
||||
- Both endpoints paginated 500 records/page via `batch-number` until a short
|
||||
page is returned.
|
||||
page is returned; pages are spaced `FUEL_API_BATCH_SLEEP` (default 4s) apart
|
||||
to stay inside the documented 30 rpm sequential-only rate limit.
|
||||
- Prices arrive as **decimal strings in pence** (`"0120.0000"` = 120.0p); some
|
||||
stations report pounds (values < 2.0 are multiplied by 100). Out-of-band
|
||||
values are dropped (50–500p sane band) so a pounds-denominated column can't
|
||||
poison the nationwide cheapest reference.
|
||||
- Fuel types mapped: `E5`/`E10` → same, `B7`/`B7_STANDARD`/`B7S`/`B7P`/`B10` →
|
||||
`DIESEL`. Others (`HVO`, `SDV`, …) are ignored — the app tracks exactly
|
||||
E5/E10/DIESEL.
|
||||
- Station snapshot cached `FUEL_CACHE_TTL` (default 300s); stale cache is
|
||||
served on upstream failure so the app never sees a hard outage.
|
||||
- Fuel types mapped: `E5`/`E10` → same, `B7`/`B7_STANDARD`/`B7S`/`B7P`/
|
||||
`B7_PREMIUM`/`B10` → `DIESEL`. Others (`HVO`, `SDV`, …) are ignored — the
|
||||
app tracks exactly E5/E10/DIESEL.
|
||||
- Station snapshot cached `FUEL_CACHE_TTL` (default 300s); a stale cache is
|
||||
refreshed in the background on the next request and stale data is served in
|
||||
the meantime, so a multi-minute sync never blocks the app's 5s timeout.
|
||||
- Base URL is `https://www.fuel-finder.service.gov.uk` (NOT
|
||||
`api.fuelfinder...` — that host doesn't resolve). Overridable per-endpoint
|
||||
via env.
|
||||
- No credentials are exposed to clients — the app calls the relay keyless.
|
||||
|
||||
## Setup
|
||||
|
||||
Reference in New Issue
Block a user