mirror of
https://github.com/catdevnull/transicion-desordenada-diablo
synced 2024-11-15 02:21:39 +00:00
mostrar reintentos y agregar random al wait de throttle
This commit is contained in:
parent
cf46317d7b
commit
fb7dea8b7d
1 changed files with 7 additions and 1 deletions
|
@ -26,6 +26,8 @@ const nConnections = process.env.N_THREADS
|
||||||
? parseInt(process.env.N_THREADS)
|
? parseInt(process.env.N_THREADS)
|
||||||
: 8;
|
: 8;
|
||||||
|
|
||||||
|
const REPORT_RETRIES = process.env.REPORT_RETRIES === "true" || false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @argument {URL} url
|
* @argument {URL} url
|
||||||
* @argument {number} attempts
|
* @argument {number} attempts
|
||||||
|
@ -43,7 +45,9 @@ export async function customRequestWithLimitsAndRetries(url, attempts = 0) {
|
||||||
(error.code === 503 && url.host === "cdn.buenosaires.gob.ar")) &&
|
(error.code === 503 && url.host === "cdn.buenosaires.gob.ar")) &&
|
||||||
attempts < 15
|
attempts < 15
|
||||||
) {
|
) {
|
||||||
await wait(15000);
|
if (REPORT_RETRIES)
|
||||||
|
console.debug(`reintentando(status)[${attempts}] ${url.toString()}`);
|
||||||
|
await wait(15000 + Math.random() * 10000);
|
||||||
return await customRequestWithLimitsAndRetries(url, attempts + 1);
|
return await customRequestWithLimitsAndRetries(url, attempts + 1);
|
||||||
}
|
}
|
||||||
// si no fue un error de http, reintentar hasta 3 veces con ~10 segundos de por medio
|
// si no fue un error de http, reintentar hasta 3 veces con ~10 segundos de por medio
|
||||||
|
@ -52,6 +56,8 @@ export async function customRequestWithLimitsAndRetries(url, attempts = 0) {
|
||||||
!(error instanceof TooManyRedirectsError) &&
|
!(error instanceof TooManyRedirectsError) &&
|
||||||
attempts < 7
|
attempts < 7
|
||||||
) {
|
) {
|
||||||
|
if (REPORT_RETRIES)
|
||||||
|
console.debug(`reintentando[${attempts}] ${url.toString()}`);
|
||||||
await wait(5000 + Math.random() * 10000);
|
await wait(5000 + Math.random() * 10000);
|
||||||
return await customRequestWithLimitsAndRetries(url, attempts + 1);
|
return await customRequestWithLimitsAndRetries(url, attempts + 1);
|
||||||
} else throw error;
|
} else throw error;
|
||||||
|
|
Loading…
Reference in a new issue