From 4fcc819d5c08b3ad5c62859f0587b883c9797b07 Mon Sep 17 00:00:00 2001 From: Chris Lample Date: Mon, 25 Mar 2024 15:36:09 +0100 Subject: [PATCH] fix: allow disabling smart retries [gh-943] (#944) --- packages/cli/src/constructs/check-group.ts | 11 +++++++++-- packages/cli/src/constructs/check.ts | 11 +++++++++-- packages/cli/src/constructs/retry-strategy.ts | 9 ++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/constructs/check-group.ts b/packages/cli/src/constructs/check-group.ts index 70f0eca4..c4878493 100644 --- a/packages/cli/src/constructs/check-group.ts +++ b/packages/cli/src/constructs/check-group.ts @@ -282,7 +282,6 @@ export class CheckGroup extends Construct { name: this.name, activated: this.activated, muted: this.muted, - doubleCheck: this.doubleCheck, tags: this.tags, locations: this.locations, runtimeId: this.runtimeId, @@ -295,7 +294,15 @@ export class CheckGroup extends Construct { localTearDownScript: this.localTearDownScript, apiCheckDefaults: this.apiCheckDefaults, environmentVariables: this.environmentVariables, - retryStrategy: this.retryStrategy, + // The backend doesn't actually support the `NO_RETRIES` type, it uses `null` instead. + retryStrategy: this.retryStrategy?.type === 'NO_RETRIES' + ? null + : this.retryStrategy, + // When `retryStrategy: NO_RETRIES` and `doubleCheck: undefined`, we want to let the user disable all retries. + // The backend has a Joi default of `doubleCheck: true`, though, so we need special handling for this case. + doubleCheck: this.doubleCheck === undefined && this.retryStrategy?.type === 'NO_RETRIES' + ? false + : this.doubleCheck, runParallel: this.runParallel, alertSettings: this.alertSettings, useGlobalAlertSettings: this.useGlobalAlertSettings, diff --git a/packages/cli/src/constructs/check.ts b/packages/cli/src/constructs/check.ts index ea055302..87472447 100644 --- a/packages/cli/src/constructs/check.ts +++ b/packages/cli/src/constructs/check.ts @@ -222,7 +222,6 @@ export abstract class Check extends Construct { name: this.name, activated: this.activated, muted: this.muted, - doubleCheck: this.doubleCheck, shouldFail: this.shouldFail, runtimeId: this.runtimeId, locations: this.locations, @@ -235,7 +234,15 @@ export abstract class Check extends Construct { frequencyOffset: this.frequencyOffset, groupId: this.groupId, environmentVariables: this.environmentVariables, - retryStrategy: this.retryStrategy, + // The backend doesn't actually support the `NO_RETRIES` type, it uses `null` instead. + retryStrategy: this.retryStrategy?.type === 'NO_RETRIES' + ? null + : this.retryStrategy, + // When `retryStrategy: NO_RETRIES` and `doubleCheck: undefined`, we want to let the user disable all retries. + // The backend has a Joi default of `doubleCheck: true`, though, so we need special handling for this case. + doubleCheck: this.doubleCheck === undefined && this.retryStrategy?.type === 'NO_RETRIES' + ? false + : this.doubleCheck, alertSettings: this.alertSettings, useGlobalAlertSettings: this.useGlobalAlertSettings, runParallel: this.runParallel, diff --git a/packages/cli/src/constructs/retry-strategy.ts b/packages/cli/src/constructs/retry-strategy.ts index 731e29f2..9c5bddd1 100644 --- a/packages/cli/src/constructs/retry-strategy.ts +++ b/packages/cli/src/constructs/retry-strategy.ts @@ -1,4 +1,4 @@ -export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' +export type RetryStrategyType = 'LINEAR' | 'EXPONENTIAL' | 'FIXED' | 'NO_RETRIES' export interface RetryStrategy { type: RetryStrategyType, @@ -55,6 +55,13 @@ export class RetryStrategyBuilder { return RetryStrategyBuilder.retryStrategy('EXPONENTIAL', options) } + /** + * No retries are performed. + */ + static noRetries (): RetryStrategy { + return RetryStrategyBuilder.retryStrategy('NO_RETRIES') + } + private static retryStrategy (type: RetryStrategyType, options?: RetryStrategyOptions): RetryStrategy { return { type,