1
1
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider" ;
2
2
import { Provider , RetryStrategy } from "@aws-sdk/types" ;
3
3
4
- import { DEFAULT_MAX_ATTEMPTS , DEFAULT_RETRY_MODE } from "./config" ;
4
+ import { AdaptiveRetryStrategy } from "./AdaptiveRetryStrategy" ;
5
+ import { DEFAULT_MAX_ATTEMPTS , DEFAULT_RETRY_MODE , RETRY_MODES } from "./config" ;
5
6
import { StandardRetryStrategy } from "./StandardRetryStrategy" ;
6
7
7
8
export const ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS" ;
@@ -38,6 +39,15 @@ export interface RetryInputConfig {
38
39
* The strategy to retry the request. Using built-in exponential backoff strategy by default.
39
40
*/
40
41
retryStrategy ?: RetryStrategy ;
42
+ /**
43
+ * Specifies which retry algorithm to use.
44
+ */
45
+ retryMode ?: string ;
46
+ /**
47
+ * Specifies provider for retry algorithm to use.
48
+ * @internal
49
+ */
50
+ retryModeProvider : Provider < string > ;
41
51
}
42
52
43
53
interface PreviouslyResolved { }
@@ -49,15 +59,24 @@ export interface RetryResolvedConfig {
49
59
/**
50
60
* Resolved value for input config {@link RetryInputConfig.retryStrategy}
51
61
*/
52
- retryStrategy : RetryStrategy ;
62
+ retryStrategy : Provider < RetryStrategy > ;
53
63
}
54
64
55
65
export const resolveRetryConfig = < T > ( input : T & PreviouslyResolved & RetryInputConfig ) : T & RetryResolvedConfig => {
56
66
const maxAttempts = normalizeMaxAttempts ( input . maxAttempts ) ;
57
67
return {
58
68
...input ,
59
69
maxAttempts,
60
- retryStrategy : input . retryStrategy || new StandardRetryStrategy ( maxAttempts ) ,
70
+ retryStrategy : async ( ) => {
71
+ if ( input . retryStrategy ) {
72
+ return input . retryStrategy ;
73
+ }
74
+ const retryMode = input . retryMode || ( await input . retryModeProvider ( ) ) ;
75
+ if ( retryMode === RETRY_MODES . adaptive ) {
76
+ return new AdaptiveRetryStrategy ( maxAttempts ) ;
77
+ }
78
+ return new StandardRetryStrategy ( maxAttempts ) ;
79
+ } ,
61
80
} ;
62
81
} ;
63
82
0 commit comments