* WIP * Add debug * Dedupe inserts * Add deterministic ordering * Fix whitespaces * Update insta * Add integration test script * Rename * Add test * Working for non-deletes * omg it mostly works for deletes * Isdeleted fix * remove created dates * update api * Take document id * No max attempt * works * Use string uuids * . * working!!!! (hopefully) * Improve bundling * Add module * lint * . * lint * Fix CI * use toolchain * clean up * Add useSlowFileEvents * Delete fuzz * Fix CI * use docker * fix script * clean up * Clean up * change node version * Build docker image on every commit * fix ci * 1 db per vault * Add scritps folder * Bump versions * Lint * . * Fix tests for real * Style * . * try * Consistent ordering * Fix tests * hmm * . * Clean up diff * Fixes * . * Fix version bump * . * . * .
38 lines
973 B
TypeScript
38 lines
973 B
TypeScript
import * as fetchRetryFactory from "fetch-retry";
|
|
import type { RequestInitRetryParams } from "fetch-retry";
|
|
import type { Logger } from "../tracing/logger";
|
|
|
|
function getUrlFromInput(input: RequestInfo | URL): string {
|
|
if (input instanceof URL) {
|
|
return input.href;
|
|
}
|
|
if (typeof input === "string") {
|
|
return input;
|
|
}
|
|
return input.url;
|
|
}
|
|
|
|
export function retriedFetchFactory(
|
|
logger: Logger,
|
|
fetch: typeof globalThis.fetch = globalThis.fetch
|
|
) {
|
|
return async (
|
|
input: RequestInfo | URL,
|
|
init: RequestInitRetryParams<typeof fetch> = {}
|
|
): Promise<Response> => {
|
|
return fetchRetryFactory.default(fetch)(input, {
|
|
retryOn: function (attempt, error, response) {
|
|
if (error !== null || !response || response.status >= 500) {
|
|
logger.warn(
|
|
`Retrying fetch for ${getUrlFromInput(input)}, attempt ${attempt}`
|
|
);
|
|
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
retryDelay: (attempt) => Math.pow(1.5, attempt) * 500,
|
|
...init
|
|
});
|
|
};
|
|
}
|