From fb7dea8b7d64d8a9d69abb0297e05179ee60861d Mon Sep 17 00:00:00 2001 From: Nulo Date: Mon, 18 Dec 2023 13:43:17 -0300 Subject: [PATCH] mostrar reintentos y agregar random al wait de throttle --- downloader/network.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/downloader/network.js b/downloader/network.js index 845b38a..551e720 100644 --- a/downloader/network.js +++ b/downloader/network.js @@ -26,6 +26,8 @@ const nConnections = process.env.N_THREADS ? parseInt(process.env.N_THREADS) : 8; +const REPORT_RETRIES = process.env.REPORT_RETRIES === "true" || false; + /** * @argument {URL} url * @argument {number} attempts @@ -43,7 +45,9 @@ export async function customRequestWithLimitsAndRetries(url, attempts = 0) { (error.code === 503 && url.host === "cdn.buenosaires.gob.ar")) && 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); } // 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) && attempts < 7 ) { + if (REPORT_RETRIES) + console.debug(`reintentando[${attempts}] ${url.toString()}`); await wait(5000 + Math.random() * 10000); return await customRequestWithLimitsAndRetries(url, attempts + 1); } else throw error;