From: Jérôme Benoit Date: Fri, 25 Aug 2023 16:49:22 +0000 (+0200) Subject: refactor: cleanup exponential delay code X-Git-Tag: v2.6.35~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=147be6fe188035c47548d07ef1f7cd884bd85f60;p=poolifier.git refactor: cleanup exponential delay code Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc.js b/.eslintrc.js index e7cf2abc..a6ad5b1d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -48,6 +48,7 @@ module.exports = defineConfig({ 'comparator', 'cpu', 'cpus', + 'cryptographically', 'ctx', 'deprecations', 'deque', diff --git a/src/utils.ts b/src/utils.ts index b5fb9afe..f1c0d923 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -75,16 +75,16 @@ export const sleep = async (ms: number): Promise => { * Computes the retry delay in milliseconds using an exponential back off algorithm. * * @param retryNumber - The number of retries that have already been attempted - * @param maxDelayRatio - The maximum ratio of the delay that can be randomized + * @param delayFactor - The base delay factor in milliseconds * @returns Delay in milliseconds * @internal */ export const exponentialDelay = ( retryNumber = 0, - maxDelayRatio = 0.2 + delayFactor = 100 ): number => { - const delay = Math.pow(2, retryNumber) * 100 - const randomSum = delay * maxDelayRatio * secureRandom() // 0-(maxDelayRatio*100)% of the delay + const delay = Math.pow(2, retryNumber) * delayFactor + const randomSum = delay * 0.2 * secureRandom() // 0-20% of the delay return delay + randomSum }