Skip to content

Commit bc7eab9

Browse files
committed
feat: add codegen support for singleRetry
1 parent 958331b commit bc7eab9

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/cli/src/constructs/retry-strategy-codegen.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,52 @@ export type RetryStrategyResource = RetryStrategy
66
export function valueForRetryStrategy (genfile: GeneratedFile, strategy?: RetryStrategyResource | null): Value {
77
genfile.namedImport('RetryStrategyBuilder', 'checkly/constructs')
88

9-
function buildCommonOptions (
9+
function buildBaseBackoffSecondsOption (
1010
options: RetryStrategyOptions,
1111
builder: ObjectValueBuilder,
1212
): void {
1313
if (options.baseBackoffSeconds) {
1414
builder.number('baseBackoffSeconds', options.baseBackoffSeconds)
1515
}
16+
}
1617

18+
function buildMaxRetriesOption (
19+
options: RetryStrategyOptions,
20+
builder: ObjectValueBuilder,
21+
): void {
1722
if (options.maxRetries) {
1823
builder.number('maxRetries', options.maxRetries)
1924
}
25+
}
2026

27+
function buildMaxDurationSecondsOption (
28+
options: RetryStrategyOptions,
29+
builder: ObjectValueBuilder,
30+
): void {
2131
if (options.maxDurationSeconds) {
2232
builder.number('maxDurationSeconds', options.maxDurationSeconds)
2333
}
34+
}
2435

36+
function buildSameRegionOption (
37+
options: RetryStrategyOptions,
38+
builder: ObjectValueBuilder,
39+
): void {
2540
if (options.sameRegion !== undefined) {
2641
builder.boolean('sameRegion', options.sameRegion)
2742
}
2843
}
2944

45+
function buildCommonOptions (
46+
options: RetryStrategyOptions,
47+
builder: ObjectValueBuilder,
48+
): void {
49+
buildBaseBackoffSecondsOption(options, builder)
50+
buildMaxRetriesOption(options, builder)
51+
buildMaxDurationSecondsOption(options, builder)
52+
buildSameRegionOption(options, builder)
53+
}
54+
3055
if (strategy === null || strategy === undefined) {
3156
return expr(ident('RetryStrategyBuilder'), builder => {
3257
builder.member(ident('noRetries'))
@@ -64,6 +89,16 @@ export function valueForRetryStrategy (genfile: GeneratedFile, strategy?: RetryS
6489
})
6590
})
6691
})
92+
case 'SINGLE':
93+
return expr(ident('RetryStrategyBuilder'), builder => {
94+
builder.member(ident('singleRetry'))
95+
builder.call(builder => {
96+
builder.object(builder => {
97+
buildBaseBackoffSecondsOption(strategy, builder)
98+
buildSameRegionOption(strategy, builder)
99+
})
100+
})
101+
})
67102
case 'NO_RETRIES':
68103
return expr(ident('RetryStrategyBuilder'), builder => {
69104
builder.member(ident('noRetries'))

0 commit comments

Comments
 (0)