Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
27 lines
1.3 KiB
Plaintext
27 lines
1.3 KiB
Plaintext
import { getCurrentDate } from '../utilities/getCurrentDate.js';
|
|
export function calculateBackoffWaitUntil({ retriesConfig, totalTried }) {
|
|
let waitUntil = getCurrentDate();
|
|
if (typeof retriesConfig === 'object') {
|
|
if (retriesConfig.backoff) {
|
|
if (retriesConfig.backoff.type === 'fixed') {
|
|
waitUntil = retriesConfig.backoff.delay ? new Date(getCurrentDate().getTime() + retriesConfig.backoff.delay) : getCurrentDate();
|
|
} else if (retriesConfig.backoff.type === 'exponential') {
|
|
// 2 ^ (attempts - 1) * delay (current attempt is not included in totalTried, thus no need for -1)
|
|
const delay = retriesConfig.backoff.delay ? retriesConfig.backoff.delay : 0;
|
|
waitUntil = new Date(getCurrentDate().getTime() + Math.pow(2, totalTried) * delay);
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
const differenceInMSBetweenNowAndWaitUntil = waitUntil.getTime() - getCurrentDate().getTime()
|
|
|
|
const differenceInSBetweenNowAndWaitUntil = differenceInMSBetweenNowAndWaitUntil / 1000
|
|
console.log('Calculated backoff', {
|
|
differenceInMSBetweenNowAndWaitUntil,
|
|
differenceInSBetweenNowAndWaitUntil,
|
|
retriesConfig,
|
|
totalTried,
|
|
})*/ return waitUntil;
|
|
}
|
|
|
|
//# sourceMappingURL=calculateBackoffWaitUntil.js.map |