@diffci.com/diffci 0.3.47 → 0.3.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -134,7 +134,7 @@ export type GitHubGet = (path: string) => Promise<{
|
|
|
134
134
|
}>;
|
|
135
135
|
export declare class StopCollection extends Error {
|
|
136
136
|
}
|
|
137
|
-
/** Paced, read-only GitHub REST client: >= 1.2 s between calls, stops on Retry-After or a
|
|
137
|
+
/** Paced, read-only GitHub REST client: >= 1.2 s between calls, stops on Retry-After, a low quota or a network that stays down. */
|
|
138
138
|
export declare function githubClient(token: string, options?: {
|
|
139
139
|
minIntervalMs?: number;
|
|
140
140
|
minRemaining?: number;
|
|
@@ -335,7 +335,9 @@ export function formatReport(report) {
|
|
|
335
335
|
}
|
|
336
336
|
export class StopCollection extends Error {
|
|
337
337
|
}
|
|
338
|
-
/**
|
|
338
|
+
/** Waits before each retry of a dropped connection or a GitHub 5xx (about 3.5 minutes in all). */
|
|
339
|
+
const NETWORK_RETRY_MS = [10_000, 30_000, 60_000, 120_000];
|
|
340
|
+
/** Paced, read-only GitHub REST client: >= 1.2 s between calls, stops on Retry-After, a low quota or a network that stays down. */
|
|
339
341
|
export function githubClient(token, options = {}) {
|
|
340
342
|
const interval = options.minIntervalMs ?? 1200;
|
|
341
343
|
const floor = options.minRemaining ?? 1000;
|
|
@@ -350,15 +352,24 @@ export function githubClient(token, options = {}) {
|
|
|
350
352
|
const request = () => fetchFn(`https://api.github.com/${path}`, {
|
|
351
353
|
headers: { Accept: "application/vnd.github+json", Authorization: `Bearer ${token}`, "User-Agent": "diffci-red-builds", "X-GitHub-Api-Version": "2022-11-28" },
|
|
352
354
|
});
|
|
355
|
+
// A dropped connection ("fetch failed") or a GitHub 5xx is not an answer: retry with growing waits, then stop
|
|
356
|
+
// and report what was read, as on a low quota. One bad minute of network must not discard an hour of calls.
|
|
353
357
|
let res;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
let failure = "";
|
|
359
|
+
for (let attempt = 0;; attempt++) {
|
|
360
|
+
try {
|
|
361
|
+
res = await request();
|
|
362
|
+
if (res.status < 500)
|
|
363
|
+
break;
|
|
364
|
+
failure = `GitHub answered HTTP ${res.status}`;
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
failure = error?.message || "the connection failed";
|
|
368
|
+
}
|
|
369
|
+
if (attempt === NETWORK_RETRY_MS.length)
|
|
370
|
+
throw new StopCollection(`${failure} on ${path.split("?")[0]}, ${attempt + 1} times`);
|
|
371
|
+
await sleep(NETWORK_RETRY_MS[attempt]);
|
|
360
372
|
last = Date.now();
|
|
361
|
-
res = await request();
|
|
362
373
|
}
|
|
363
374
|
if (res.headers.get("retry-after"))
|
|
364
375
|
throw new StopCollection(`GitHub asked to slow down (Retry-After on ${path.split("?")[0]})`);
|