@@ -7,8 +7,9 @@ export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'SINGLE' |
77export type RetryStrategyCondition = 'NETWORK_ERROR'
88
99/**
10- * Configuration for check retry behavior.
11- * Defines how and when to retry failed checks before marking them as permanently failed.
10+ * Configuration for check and monitor retry behavior.
11+ * Defines how and when to retry failed checks or monitors before marking
12+ * them as permanently failed.
1213 */
1314export interface RetryStrategy {
1415 /** The retry strategy type */
@@ -83,9 +84,45 @@ export interface RetryStrategy {
8384export type RetryStrategyOptions = Omit < RetryStrategy , 'type' >
8485
8586/**
86- * Configuration for single retry behavior .
87+ * Configuration for linear retry strategies .
8788 */
88- export interface SingleRetryStrategy extends Pick < RetryStrategy , 'baseBackoffSeconds' | 'sameRegion' > {
89+ export interface LinearRetryStrategy extends RetryStrategy {
90+ type : 'LINEAR'
91+ }
92+
93+ /**
94+ * Options for configuring linear retry strategy behavior.
95+ */
96+ export type LinearRetryStrategyOptions = RetryStrategyOptions
97+
98+ /**
99+ * Configuration for exponential retry strategies.
100+ */
101+ export interface ExponentialRetryStrategy extends RetryStrategy {
102+ type : 'EXPONENTIAL'
103+ }
104+
105+ /**
106+ * Options for configuring exponential retry strategy behavior.
107+ */
108+ export type ExponentialRetryStrategyOptions = RetryStrategyOptions
109+
110+ /**
111+ * Configuration for fixed retry strategies.
112+ */
113+ export interface FixedRetryStrategy extends RetryStrategy {
114+ type : 'FIXED'
115+ }
116+
117+ /**
118+ * Options for configuring fixed retry strategy behavior.
119+ */
120+ export type FixedRetryStrategyOptions = RetryStrategyOptions
121+
122+ /**
123+ * Configuration for single retry strategies.
124+ */
125+ export interface SingleRetryStrategy extends Pick < RetryStrategy , 'type' | 'baseBackoffSeconds' | 'sameRegion' > {
89126 type : 'SINGLE'
90127}
91128
@@ -94,6 +131,13 @@ export interface SingleRetryStrategy extends Pick<RetryStrategy, 'baseBackoffSec
94131 */
95132export type SingleRetryStrategyOptions = Pick < RetryStrategyOptions , 'baseBackoffSeconds' | 'sameRegion' >
96133
134+ /**
135+ * Configuration for no retry retry strategies.
136+ */
137+ export interface NoRetriesRetryStrategy extends Pick < RetryStrategy , 'type' > {
138+ type : 'NO_RETRIES'
139+ }
140+
97141/**
98142 * Builder class for creating retry strategies.
99143 * Provides convenient methods to create different types of retry strategies.
@@ -144,8 +188,11 @@ export class RetryStrategyBuilder {
144188 /**
145189 * Each retry is run with the same backoff between attempts.
146190 */
147- static fixedStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
148- return RetryStrategyBuilder . retryStrategy ( 'FIXED' , options )
191+ static fixedStrategy ( options ?: FixedRetryStrategyOptions ) : FixedRetryStrategy {
192+ return {
193+ type : 'FIXED' ,
194+ ...RetryStrategyBuilder . defaults ( options ) ,
195+ }
149196 }
150197
151198 /**
@@ -154,8 +201,11 @@ export class RetryStrategyBuilder {
154201 * The delay between retries is calculated using `baseBackoffSeconds * attempt`.
155202 * For example, retries will be run with a backoff of 10s, 20s, 30s, and so on.
156203 */
157- static linearStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
158- return RetryStrategyBuilder . retryStrategy ( 'LINEAR' , options )
204+ static linearStrategy ( options ?: LinearRetryStrategyOptions ) : LinearRetryStrategy {
205+ return {
206+ type : 'LINEAR' ,
207+ ...RetryStrategyBuilder . defaults ( options ) ,
208+ }
159209 }
160210
161211 /**
@@ -164,38 +214,36 @@ export class RetryStrategyBuilder {
164214 * The delay between retries is calculated using `baseBackoffSeconds ^ attempt`.
165215 * For example, retries will be run with a backoff of 10s, 100s, 1000s, and so on.
166216 */
167- static exponentialStrategy ( options ?: RetryStrategyOptions ) : RetryStrategy {
168- return RetryStrategyBuilder . retryStrategy ( 'EXPONENTIAL' , options )
217+ static exponentialStrategy ( options ?: ExponentialRetryStrategyOptions ) : ExponentialRetryStrategy {
218+ return {
219+ type : 'EXPONENTIAL' ,
220+ ...RetryStrategyBuilder . defaults ( options ) ,
221+ }
169222 }
170223
171224 /**
172225 * A single retry will be performed.
173226 */
174- static singleRetry ( options ?: SingleRetryStrategyOptions ) : RetryStrategy {
175- const {
176- // eslint-disable-next-line @typescript-eslint/no-unused-vars
177- maxRetries,
178- // eslint-disable-next-line @typescript-eslint/no-unused-vars
179- maxDurationSeconds,
180- ...strategy
181- } = RetryStrategyBuilder . retryStrategy ( 'SINGLE' , {
182- baseBackoffSeconds : options ?. baseBackoffSeconds ,
183- sameRegion : options ?. sameRegion ,
184- } )
185-
186- return strategy
227+ static singleRetry ( options ?: SingleRetryStrategyOptions ) : SingleRetryStrategy {
228+ const { baseBackoffSeconds, sameRegion } = RetryStrategyBuilder . defaults ( options )
229+ return {
230+ type : 'SINGLE' ,
231+ baseBackoffSeconds,
232+ sameRegion,
233+ }
187234 }
188235
189236 /**
190237 * No retries are performed.
191238 */
192- static noRetries ( ) : RetryStrategy {
193- return RetryStrategyBuilder . retryStrategy ( 'NO_RETRIES' )
239+ static noRetries ( ) : NoRetriesRetryStrategy {
240+ return {
241+ type : 'NO_RETRIES' ,
242+ }
194243 }
195244
196- private static retryStrategy ( type : RetryStrategyType , options ?: RetryStrategyOptions ) : RetryStrategy {
245+ private static defaults ( options ?: RetryStrategyOptions ) : RetryStrategyOptions {
197246 return {
198- type,
199247 baseBackoffSeconds : options ?. baseBackoffSeconds ?? RetryStrategyBuilder . DEFAULT_BASE_BACKOFF_SECONDS ,
200248 maxRetries : options ?. maxRetries ?? RetryStrategyBuilder . DEFAULT_MAX_RETRIES ,
201249 maxDurationSeconds : options ?. maxDurationSeconds ?? RetryStrategyBuilder . DEFAULT_MAX_DURATION_SECONDS ,
0 commit comments