-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4953041
commit 055cb5b
Showing
6 changed files
with
308 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @fileoverview Calculate exponential backoff time | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Private | ||
// ------------------------------------------------------------------------------ | ||
|
||
// Retry intervals are between 50% and 150% of the exponentially increasing base amount | ||
const RETRY_RANDOMIZATION_FACTOR = 0.5; | ||
|
||
/** | ||
* Calculate the exponential backoff time with randomized jitter | ||
* @param {int} numRetries Which retry number this one will be | ||
* @param {int} baseInterval The base retry interval set in config | ||
* @returns {int} The number of milliseconds after which to retry | ||
*/ | ||
function getRetryTimeout(numRetries, baseInterval) { | ||
|
||
var minRandomization = 1 - RETRY_RANDOMIZATION_FACTOR; | ||
var maxRandomization = 1 + RETRY_RANDOMIZATION_FACTOR; | ||
var randomization = (Math.random() * (maxRandomization - minRandomization)) + minRandomization; | ||
var exponential = Math.pow(2, numRetries - 1); | ||
return Math.ceil(exponential * baseInterval * randomization); | ||
} | ||
|
||
module.exports = getRetryTimeout; |
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
Oops, something went wrong.