@@ -3,11 +3,34 @@ import { SdkError } from "@aws-sdk/smithy-client";
3
3
import { NO_RETRY_INCREMENT , RETRY_COST , TIMEOUT_RETRY_COST } from "./constants" ;
4
4
import { RetryQuota } from "./types" ;
5
5
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 => {
7
26
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
+
8
31
let availableCapacity = initialRetryTokens ;
9
32
10
- const getCapacityAmount = ( error : SdkError ) => ( error . name === "TimeoutError" ? TIMEOUT_RETRY_COST : RETRY_COST ) ;
33
+ const getCapacityAmount = ( error : SdkError ) => ( error . name === "TimeoutError" ? timeoutRetryCost : retryCost ) ;
11
34
12
35
const hasRetryTokens = ( error : SdkError ) => getCapacityAmount ( error ) <= availableCapacity ;
13
36
@@ -22,7 +45,7 @@ export const getDefaultRetryQuota = (initialRetryTokens: number): RetryQuota =>
22
45
} ;
23
46
24
47
const releaseRetryTokens = ( capacityReleaseAmount ?: number ) => {
25
- availableCapacity += capacityReleaseAmount ?? NO_RETRY_INCREMENT ;
48
+ availableCapacity += capacityReleaseAmount ?? noRetryIncrement ;
26
49
availableCapacity = Math . min ( availableCapacity , MAX_CAPACITY ) ;
27
50
} ;
28
51
0 commit comments