2
2
export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'SINGLE' | 'NO_RETRIES'
3
3
4
4
/**
5
- * Configuration for check retry behavior.
6
- * Defines how and when to retry failed checks before marking them as permanently failed.
5
+ * Configuration for check and monitor retry behavior.
6
+ * Defines how and when to retry failed checks or monitors before marking
7
+ * them as permanently failed.
7
8
*/
8
9
export interface RetryStrategy {
9
10
/** The retry strategy type */
@@ -68,9 +69,45 @@ export interface RetryStrategy {
68
69
export type RetryStrategyOptions = Pick < RetryStrategy , 'baseBackoffSeconds' | 'maxRetries' | 'maxDurationSeconds' | 'sameRegion' >
69
70
70
71
/**
71
- * Configuration for single retry behavior .
72
+ * Configuration for linear retry strategies .
72
73
*/
73
- export interface SingleRetryStrategy extends Pick < RetryStrategy , 'baseBackoffSeconds' | 'sameRegion' > {
74
+ export interface LinearRetryStrategy extends RetryStrategy {
75
+ type : 'LINEAR'
76
+ }
77
+
78
+ /**
79
+ * Options for configuring linear retry strategy behavior.
80
+ */
81
+ export type LinearRetryStrategyOptions = RetryStrategyOptions
82
+
83
+ /**
84
+ * Configuration for exponential retry strategies.
85
+ */
86
+ export interface ExponentialRetryStrategy extends RetryStrategy {
87
+ type : 'EXPONENTIAL'
88
+ }
89
+
90
+ /**
91
+ * Options for configuring exponential retry strategy behavior.
92
+ */
93
+ export type ExponentialRetryStrategyOptions = RetryStrategyOptions
94
+
95
+ /**
96
+ * Configuration for fixed retry strategies.
97
+ */
98
+ export interface FixedRetryStrategy extends RetryStrategy {
99
+ type : 'FIXED'
100
+ }
101
+
102
+ /**
103
+ * Options for configuring fixed retry strategy behavior.
104
+ */
105
+ export type FixedRetryStrategyOptions = RetryStrategyOptions
106
+
107
+ /**
108
+ * Configuration for single retry strategies.
109
+ */
110
+ export interface SingleRetryStrategy extends Pick < RetryStrategy , 'type' | 'baseBackoffSeconds' | 'sameRegion' > {
74
111
type : 'SINGLE'
75
112
}
76
113
@@ -79,6 +116,13 @@ export interface SingleRetryStrategy extends Pick<RetryStrategy, 'baseBackoffSec
79
116
*/
80
117
export type SingleRetryStrategyOptions = Pick < RetryStrategyOptions , 'baseBackoffSeconds' | 'sameRegion' >
81
118
119
+ /**
120
+ * Configuration for no retry retry strategies.
121
+ */
122
+ export interface NoRetriesRetryStrategy extends Pick < RetryStrategy , 'type' > {
123
+ type : 'NO_RETRIES'
124
+ }
125
+
82
126
/**
83
127
* Builder class for creating retry strategies.
84
128
* Provides convenient methods to create different types of retry strategies.
@@ -121,8 +165,11 @@ export class RetryStrategyBuilder {
121
165
/**
122
166
* Each retry is run with the same backoff between attempts.
123
167
*/
124
- static fixedStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
125
- return RetryStrategyBuilder . retryStrategy ( 'FIXED' , options )
168
+ static fixedStrategy ( options ?: FixedRetryStrategyOptions ) : FixedRetryStrategy {
169
+ return {
170
+ type : 'FIXED' ,
171
+ ...RetryStrategyBuilder . defaults ( options ) ,
172
+ }
126
173
}
127
174
128
175
/**
@@ -131,8 +178,11 @@ export class RetryStrategyBuilder {
131
178
* The delay between retries is calculated using `baseBackoffSeconds * attempt`.
132
179
* For example, retries will be run with a backoff of 10s, 20s, 30s, and so on.
133
180
*/
134
- static linearStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
135
- return RetryStrategyBuilder . retryStrategy ( 'LINEAR' , options )
181
+ static linearStrategy ( options ?: LinearRetryStrategyOptions ) : LinearRetryStrategy {
182
+ return {
183
+ type : 'LINEAR' ,
184
+ ...RetryStrategyBuilder . defaults ( options ) ,
185
+ }
136
186
}
137
187
138
188
/**
@@ -141,38 +191,36 @@ export class RetryStrategyBuilder {
141
191
* The delay between retries is calculated using `baseBackoffSeconds ^ attempt`.
142
192
* For example, retries will be run with a backoff of 10s, 100s, 1000s, and so on.
143
193
*/
144
- static exponentialStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
145
- return RetryStrategyBuilder . retryStrategy ( 'EXPONENTIAL' , options )
194
+ static exponentialStrategy ( options ?: ExponentialRetryStrategyOptions ) : ExponentialRetryStrategy {
195
+ return {
196
+ type : 'EXPONENTIAL' ,
197
+ ...RetryStrategyBuilder . defaults ( options ) ,
198
+ }
146
199
}
147
200
148
201
/**
149
202
* A single retry will be performed.
150
203
*/
151
- static singleRetry ( options ?: SingleRetryStrategyOptions ) : RetryStrategy {
152
- const {
153
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
154
- maxRetries,
155
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
156
- maxDurationSeconds,
157
- ...strategy
158
- } = RetryStrategyBuilder . retryStrategy ( 'SINGLE' , {
159
- baseBackoffSeconds : options ?. baseBackoffSeconds ,
160
- sameRegion : options ?. sameRegion ,
161
- } )
162
-
163
- return strategy
204
+ static singleRetry ( options ?: SingleRetryStrategyOptions ) : SingleRetryStrategy {
205
+ const { baseBackoffSeconds, sameRegion } = RetryStrategyBuilder . defaults ( options )
206
+ return {
207
+ type : 'SINGLE' ,
208
+ baseBackoffSeconds,
209
+ sameRegion,
210
+ }
164
211
}
165
212
166
213
/**
167
214
* No retries are performed.
168
215
*/
169
- static noRetries ( ) : RetryStrategy {
170
- return RetryStrategyBuilder . retryStrategy ( 'NO_RETRIES' )
216
+ static noRetries ( ) : NoRetriesRetryStrategy {
217
+ return {
218
+ type : 'NO_RETRIES'
219
+ }
171
220
}
172
221
173
- private static retryStrategy ( type : RetryStrategyType , options ?: RetryStrategyOptions ) : RetryStrategy {
222
+ private static defaults ( options ?: RetryStrategyOptions ) : RetryStrategyOptions {
174
223
return {
175
- type,
176
224
baseBackoffSeconds : options ?. baseBackoffSeconds ?? RetryStrategyBuilder . DEFAULT_BASE_BACKOFF_SECONDS ,
177
225
maxRetries : options ?. maxRetries ?? RetryStrategyBuilder . DEFAULT_MAX_RETRIES ,
178
226
maxDurationSeconds : options ?. maxDurationSeconds ?? RetryStrategyBuilder . DEFAULT_MAX_DURATION_SECONDS ,
0 commit comments