-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(whatislove-dev): add retry functionality for 3d party api calls …
…wd-676 (#706) * fix(root): edit cd cron expression wd-676 * feat(shared): update setAsyncTimeout signature wd-676 * feat(whatislove-dev): add retry functionality for api calls wd-676 * build(root): add cd action dispatch wd-676 * build(root): add log deploy output step wd-676
- Loading branch information
1 parent
a33c101
commit 270c554
Showing
7 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/shared/src/libs/helpers/retry-call/retry-call.helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { setAsyncTimeout } from '../set-async-timeout/set-async-timeout.helper.js' | ||
|
||
let MINIMAL_RETRY_COUNT_FOR_CALL = /** @type {const} */ (0) | ||
let RETRY_COUNT_DECREMENT_PER_CALL = /** @type {const} */ (1) | ||
|
||
/** | ||
* @template {unknown} T | ||
* @param {{ | ||
* callback: (...args: unknown[]) => T | Promise<T> | ||
* retriesCount?: number | ||
* delayMs?: number | ||
* delayFactorCount?: number | ||
* }} params | ||
* @returns {Promise<T>} | ||
*/ | ||
let retryCall = async ({ | ||
callback, | ||
delayFactorCount = 3, | ||
delayMs = 1000, | ||
retriesCount = 3, | ||
}) => { | ||
try { | ||
return await callback() | ||
} catch (error) { | ||
let hasRetries = retriesCount > MINIMAL_RETRY_COUNT_FOR_CALL | ||
|
||
if (!hasRetries) { | ||
throw error | ||
} | ||
|
||
await setAsyncTimeout(undefined, delayMs) | ||
|
||
let updatedDelayMs = delayMs * delayFactorCount | ||
let updatedTriesCount = retriesCount - RETRY_COUNT_DECREMENT_PER_CALL | ||
|
||
return retryCall({ | ||
callback, | ||
delayFactorCount, | ||
delayMs: updatedDelayMs, | ||
retriesCount: updatedTriesCount, | ||
}) | ||
} | ||
} | ||
|
||
export { retryCall } |
4 changes: 2 additions & 2 deletions
4
packages/shared/src/libs/helpers/set-async-timeout/set-async-timeout.helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters