Keep reading a Liga season when one month of the calendar is slow.
ci / rust (pull_request) Successful in 11m31s
ci / typescript (pull_request) Successful in 15m14s

A single timed-out month aborted the whole year and left a few games stored, which then hid the rest. That month is tried again and the other months are still saved.
This commit is contained in:
spark committed 2026-10-19 04:21:59 +01:00
1 parent a8f6a0f03d
commit 6e956f0ff8
2 files changed
+17 -6

No files matched your search

+4 -3
View File
@@ -70,8 +70,8 @@ export interface OfficialData {
const TIMEOUT_MS = 20_000;
async function get(fetcher: Fetch, url: string, headers: Record<string, string>, as: "json" | "text") {
const res = await fetcher(url, { headers, signal: AbortSignal.timeout(TIMEOUT_MS) });
async function get(fetcher: Fetch, url: string, headers: Record<string, string>, as: "json" | "text", timeoutMs = TIMEOUT_MS) {
const res = await fetcher(url, { headers, signal: AbortSignal.timeout(timeoutMs) });
if (!res.ok) throw new Error(`${new URL(url).host} ${new URL(url).pathname} ${res.status}`);
return as === "json" ? res.json() : res.text();
}
@@ -130,7 +130,8 @@ export class LigaProvider {
private async api(path: string, params: Record<string, string>): Promise<unknown> {
const u = new URL(`${LigaProvider.BASE}/${path}`);
for (const [k, v] of Object.entries(params)) u.searchParams.set(k, v);
return get(this.fetcher, u.toString(), LigaProvider.HEADERS, "json");
// The calendar is slow from the archive host. A short timeout used to abort a whole season after one month.
return get(this.fetcher, u.toString(), LigaProvider.HEADERS, "json", 45_000);
}
async teams(competition: string, season: string): Promise<TeamData[]> {
+13 -3
View File
@@ -164,9 +164,19 @@ export class SportsService {
const asked = season.replace(/\D/g, "");
let saved = 0;
for (const month of [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6]) {
for (const f of await this.liga.month(month, season)) {
// Only a season Liga itself named. A fixture id is updated in place, so guessing the season we asked
// for would move another year's game onto this one.
// One slow month must not drop the rest of the year. It is tried twice; the months already read stay.
let fixtures: Awaited<ReturnType<LigaProvider["month"]>> = [];
for (let attempt = 0; attempt < 2; attempt++) {
try {
fixtures = await this.liga.month(month, season);
break;
} catch (err) {
fixtures = [];
this.deps.log.warn({ err, season, month, attempt }, "sports: liga month not read");
}
}
for (const f of fixtures) {
// Only a season Liga itself named. The fixture id includes that season, so another year is another row.
if (!f.seasonNamed) continue;
const theirs = f.season.replace(/\D/g, "");
if (theirs !== asked) continue;