22export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'SINGLE' | 'NO_RETRIES'
33
44/**
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.
78 */
89export interface RetryStrategy {
910 /** The retry strategy type */
@@ -68,9 +69,45 @@ export interface RetryStrategy {
6869export type RetryStrategyOptions = Pick < RetryStrategy , 'baseBackoffSeconds' | 'maxRetries' | 'maxDurationSeconds' | 'sameRegion' >
6970
7071/**
71- * Configuration for single retry behavior .
72+ * Configuration for linear retry strategies .
7273 */
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' > {
74111 type : 'SINGLE'
75112}
76113
@@ -79,6 +116,13 @@ export interface SingleRetryStrategy extends Pick<RetryStrategy, 'baseBackoffSec
79116 */
80117export type SingleRetryStrategyOptions = Pick < RetryStrategyOptions , 'baseBackoffSeconds' | 'sameRegion' >
81118
119+ /**
120+ * Configuration for no retry retry strategies.
121+ */
122+ export interface NoRetriesRetryStrategy extends Pick < RetryStrategy , 'type' > {
123+ type : 'NO_RETRIES'
124+ }
125+
82126/**
83127 * Builder class for creating retry strategies.
84128 * Provides convenient methods to create different types of retry strategies.
@@ -121,8 +165,11 @@ export class RetryStrategyBuilder {
121165 /**
122166 * Each retry is run with the same backoff between attempts.
123167 */
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+ }
126173 }
127174
128175 /**
@@ -131,8 +178,11 @@ export class RetryStrategyBuilder {
131178 * The delay between retries is calculated using `baseBackoffSeconds * attempt`.
132179 * For example, retries will be run with a backoff of 10s, 20s, 30s, and so on.
133180 */
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+ }
136186 }
137187
138188 /**
@@ -141,38 +191,36 @@ export class RetryStrategyBuilder {
141191 * The delay between retries is calculated using `baseBackoffSeconds ^ attempt`.
142192 * For example, retries will be run with a backoff of 10s, 100s, 1000s, and so on.
143193 */
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+ }
146199 }
147200
148201 /**
149202 * A single retry will be performed.
150203 */
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+ }
164211 }
165212
166213 /**
167214 * No retries are performed.
168215 */
169- static noRetries ( ) : RetryStrategy {
170- return RetryStrategyBuilder . retryStrategy ( 'NO_RETRIES' )
216+ static noRetries ( ) : NoRetriesRetryStrategy {
217+ return {
218+ type : 'NO_RETRIES'
219+ }
171220 }
172221
173- private static retryStrategy ( type : RetryStrategyType , options ?: RetryStrategyOptions ) : RetryStrategy {
222+ private static defaults ( options ?: RetryStrategyOptions ) : RetryStrategyOptions {
174223 return {
175- type,
176224 baseBackoffSeconds : options ?. baseBackoffSeconds ?? RetryStrategyBuilder . DEFAULT_BASE_BACKOFF_SECONDS ,
177225 maxRetries : options ?. maxRetries ?? RetryStrategyBuilder . DEFAULT_MAX_RETRIES ,
178226 maxDurationSeconds : options ?. maxDurationSeconds ?? RetryStrategyBuilder . DEFAULT_MAX_DURATION_SECONDS ,
0 commit comments