From f07cd133d3166688c5883f64c6491665f38bba78 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Mon, 21 Nov 2022 10:15:43 +0100 Subject: [PATCH] fix: fix retry max-out bug (#2121) * fix: fix retry max-out bug This commit makes sure that the retry function tests all PATs. * style: format code * test: fix retry tests * style: format code --- src/common/retryer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/retryer.js b/src/common/retryer.js index 77f69d3..e54eedb 100644 --- a/src/common/retryer.js +++ b/src/common/retryer.js @@ -1,5 +1,11 @@ import { CustomError, logger } from "./utils.js"; +// Script variables. +const PATs = Object.keys(process.env).filter((key) => + /PAT_\d*$/.exec(key), +).length; +const RETRIES = PATs ? PATs : 7; + /** * Try to execute the fetcher function until it succeeds or the max number of retries is reached. * @@ -10,7 +16,7 @@ import { CustomError, logger } from "./utils.js"; * @returns Promise */ const retryer = async (fetcher, variables, retries = 0) => { - if (retries > 7) { + if (retries > RETRIES) { throw new CustomError("Maximum retries exceeded", CustomError.MAX_RETRY); } try {