Skip to content

Commit 3110d62

Browse files
authored
chore(middleware-retry): add options to StandardRetryStrategy (#2458)
1 parent b3d13a2 commit 3110d62

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/middleware-retry/src/defaultRetryQuota.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ import { SdkError } from "@aws-sdk/smithy-client";
33
import { NO_RETRY_INCREMENT, RETRY_COST, TIMEOUT_RETRY_COST } from "./constants";
44
import { RetryQuota } from "./types";
55

6-
export const getDefaultRetryQuota = (initialRetryTokens: number): RetryQuota => {
6+
export interface DefaultRetryQuotaOptions {
7+
/**
8+
* The total amount of retry token to be incremented from retry token balance
9+
* if an SDK operation invocation succeeds without requiring a retry request.
10+
*/
11+
noRetryIncrement?: number;
12+
13+
/**
14+
* The total amount of retry tokens to be decremented from retry token balance.
15+
*/
16+
retryCost?: number;
17+
18+
/**
19+
* The total amount of retry tokens to be decremented from retry token balance
20+
* when a throttling error is encountered.
21+
*/
22+
timeoutRetryCost?: number;
23+
}
24+
25+
export const getDefaultRetryQuota = (initialRetryTokens: number, options?: DefaultRetryQuotaOptions): RetryQuota => {
726
const MAX_CAPACITY = initialRetryTokens;
27+
const noRetryIncrement = options?.noRetryIncrement ?? NO_RETRY_INCREMENT;
28+
const retryCost = options?.retryCost ?? RETRY_COST;
29+
const timeoutRetryCost = options?.timeoutRetryCost ?? TIMEOUT_RETRY_COST;
30+
831
let availableCapacity = initialRetryTokens;
932

10-
const getCapacityAmount = (error: SdkError) => (error.name === "TimeoutError" ? TIMEOUT_RETRY_COST : RETRY_COST);
33+
const getCapacityAmount = (error: SdkError) => (error.name === "TimeoutError" ? timeoutRetryCost : retryCost);
1134

1235
const hasRetryTokens = (error: SdkError) => getCapacityAmount(error) <= availableCapacity;
1336

@@ -22,7 +45,7 @@ export const getDefaultRetryQuota = (initialRetryTokens: number): RetryQuota =>
2245
};
2346

2447
const releaseRetryTokens = (capacityReleaseAmount?: number) => {
25-
availableCapacity += capacityReleaseAmount ?? NO_RETRY_INCREMENT;
48+
availableCapacity += capacityReleaseAmount ?? noRetryIncrement;
2649
availableCapacity = Math.min(availableCapacity, MAX_CAPACITY);
2750
};
2851

0 commit comments

Comments
 (0)