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
This commit is contained in:
Rick Staa 2022-11-21 10:15:43 +01:00 committed by GitHub
parent 42a4b6f60a
commit f07cd133d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<retryer>
*/
const retryer = async (fetcher, variables, retries = 0) => {
if (retries > 7) {
if (retries > RETRIES) {
throw new CustomError("Maximum retries exceeded", CustomError.MAX_RETRY);
}
try {