Skip to content

Commit

Permalink
cleanup retry policies, fixes slackapi#734
Browse files Browse the repository at this point in the history
  • Loading branch information
aoberoi committed Mar 12, 2019
1 parent fc1edaf commit 88e1be8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class WebClient extends EventEmitter<WebClientEvent> {
logger = undefined,
logLevel = LogLevel.INFO,
maxRequestConcurrency = 3,
retryConfig = retryPolicies.retryForeverExponentialCappedRandom,
retryConfig = retryPolicies.tenRetriesInAboutThirtyMinutes,
agent = undefined,
tls = undefined,
pageSize = 200,
Expand Down
30 changes: 8 additions & 22 deletions src/retry-policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@ export interface RetryOptions extends Options {
}

/**
* Keep retrying forever, with an exponential backoff.
* The default retry policy. Retry up to 10 times, over the span of about 30 minutes. It's not exact because
* randomization has been added to prevent a stampeding herd problem (if all instances in your application are retrying
* a request at the exact same intervals, they are more likely to cause failures for each other).
*/
export const retryForeverExponential: RetryOptions = {
forever: true,
};

/**
* Same as {@link retryForeverExponential}, but capped at 30 minutes.
* TODO: should this name really have "forever" in it? if not, remove from all the derived names below
*/
export const retryForeverExponentialCapped: RetryOptions = Object.assign({}, retryForeverExponential, {
maxTimeout: 30 * 60 * 1000,
});

/**
* Same as {@link retryForeverExponentialCapped}, but with randomization to
* prevent stampeding herds.
*/
export const retryForeverExponentialCappedRandom: RetryOptions = Object.assign({}, retryForeverExponentialCapped, {
export const tenRetriesInAboutThirtyMinutes: RetryOptions = {
retries: 10,
factor: 1.96821,
randomize: true,
});
};

/**
* Short & sweet, five retries in five minutes and then bail.
Expand All @@ -46,9 +34,7 @@ export const rapidRetryPolicy: RetryOptions = {
};

const policies = {
retryForeverExponential,
retryForeverExponentialCapped,
retryForeverExponentialCappedRandom,
tenRetriesInAboutThirtyMinutes,
fiveRetriesInFiveMinutes,
rapidRetryPolicy,
};
Expand Down

0 comments on commit 88e1be8

Please sign in to comment.