Skip to content

Commit e731d91

Browse files
committed
ci: retry spec fetch with backoff
A transient CDN 520 failed the sdk-typescript scheduled release on 2026-07-07; the same single-shot fetch lives here. Retry up to 5 times with exponential backoff so the daily release run survives upstream blips.
1 parent 9dfdcdf commit e731d91

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

scripts/generate.mjs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,27 @@ const TESTS_GENERATED_DIR = path.join(ROOT, 'tests', 'Generated');
3434
// 1. Fetch + patch + persist spec
3535
// ---------------------------------------------------------------------------
3636

37-
console.log(`[generate] fetching ${SPEC_URL}`);
38-
const response = await fetch(SPEC_URL, { headers: { 'Cache-Control': 'no-cache' } });
39-
if (!response.ok) {
40-
console.error(`[generate] fetch failed: ${response.status} ${response.statusText}`);
41-
process.exit(1);
37+
/** Retry with exponential backoff: a transient upstream error (e.g. a CDN 520) must not fail the daily release run. */
38+
async function fetchSpec(url, attempts = 5) {
39+
for (let attempt = 1; ; attempt++) {
40+
try {
41+
const res = await fetch(url, { headers: { 'Cache-Control': 'no-cache' } });
42+
if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}`);
43+
return await res.json();
44+
} catch (err) {
45+
if (attempt === attempts) {
46+
console.error(`[generate] fetch failed after ${attempts} attempts: ${err.message}`);
47+
process.exit(1);
48+
}
49+
const delay = 2 ** attempt;
50+
console.warn(`[generate] fetch attempt ${attempt}/${attempts} failed (${err.message}), retrying in ${delay}s`);
51+
await new Promise((resolve) => setTimeout(resolve, delay * 1000));
52+
}
53+
}
4254
}
43-
const spec = await response.json();
55+
56+
console.log(`[generate] fetching ${SPEC_URL}`);
57+
const spec = await fetchSpec(SPEC_URL);
4458

4559
// Patch server URL to absolute production URL so the connector works without
4660
// users supplying a baseUrl (matches the TS + Python SDKs).

0 commit comments

Comments
 (0)