fix(ski-routing): keep one job's timeout to itself and bound the area refresh

The router thread now takes one job at a time from a queue kept on the
main thread, so a job's clock starts when the thread takes it up. A job
that times out ends only its own thread, and only while that thread is
still the current one; the jobs in line go to a fresh thread instead of
waiting out their own timers and killing the new thread in turn. A
thread that dies fails the job it held, and a thread that cannot start
fails each job on its own.

- the daily refresh fetches changed areas two at a time and stops once
  the TREK Places breaker opens; the rest keep their older copies
- the winter index cap is on the unpacked JSON fetch hands over, so it
  follows from the host's 8 MB gzip cap (64 MB) instead of matching it
- a build name is read to the rule a ski tour stores it by, so a build
  TREK could not save is refused when the winter layer is read
- an unused import in the piste router contract is gone
This commit is contained in:
Maurice
2026-10-20 21:06:48 +02:00
parent 2d0c0597b3
commit 1d72fbd25f
12 changed files with 245 additions and 47 deletions
@@ -1,5 +1,6 @@
import { readEnv } from '../../app-config';
import {
trekPlacesHeldBack,
trekPlacesWinterArea,
trekPlacesWinterIndex,
trekPlacesWinterMeta,
@@ -24,6 +25,11 @@ export class TrekPlacesWinterService {
return readEnv().maps.trekPlacesEnabled;
}
/** Whether the circuit breaker holds requests back after the host failed several times. */
heldBack(): boolean {
return trekPlacesHeldBack();
}
meta(): Promise<WinterMeta> {
return trekPlacesWinterMeta();
}
+9 -2
View File
@@ -15,6 +15,7 @@ import { readEnv, getAppUrl } from '../../app-config';
import { toApiLang } from './maps.helpers';
import {
normalizePlaceWebsite,
skiRouteBuildSchema,
winterIndexRowSchema,
winterMetaSchema,
type WinterIndex,
@@ -887,7 +888,13 @@ export async function trekPlacesRoutes(
export type TrekPlacesWinterBody = { status: 'not_modified' } | { status: 'ok'; bytes: Buffer; etag: string | null };
const WINTER_META = { timeoutMs: 5_000, maxBytes: 64 * 1024 };
const WINTER_INDEX = { timeoutMs: 15_000, maxBytes: 8 * 1024 * 1024 };
/**
* The host caps the index it stores at 8 MB of gzip and sends it packed;
* fetch unpacks it before it is read, so the cap here is on the unpacked
* JSON, which is several times larger. 64 MB holds whatever the host's cap
* lets through and still bounds a body that is not the index at all.
*/
const WINTER_INDEX = { timeoutMs: 15_000, maxBytes: 64 * 1024 * 1024 };
const WINTER_AREA = { timeoutMs: 30_000, maxBytes: 32 * 1024 * 1024 };
const WINTER_AREA_ID = /^[a-z]:[0-9]+(-[0-9a-z]+)?$/;
@@ -901,7 +908,7 @@ function bareTag(value: string | null): string | null {
/** The head of the index; its rows are read one by one. */
const winterIndexHeadSchema = z.object({
build: z.string().min(1).max(40),
build: skiRouteBuildSchema,
format: z.number().int(),
areas: z.array(z.unknown()),
});