async cancelTransformation()

in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts [252:298]


    async cancelTransformation(request: CancelTransformRequest) {
        let cancelTransformationAttempt = 0
        let cancelTransformationMaxAttempts = 3
        while (true) {
            try {
                const stopCodeTransformationRequest = {
                    transformationJobId: request.TransformationJobId,
                } as StopTransformationRequest
                this.logging.log(
                    'Sending CancelTransformRequest with job Id: ' + stopCodeTransformationRequest.transformationJobId
                )
                const response = await this.serviceManager
                    .getCodewhispererService()
                    .codeModernizerStopCodeTransformation(stopCodeTransformationRequest)
                this.logging.log('Transformation status: ' + response.transformationStatus)
                let status: CancellationJobStatus
                switch (response.transformationStatus) {
                    case 'STOPPED':
                        status = CancellationJobStatus.SUCCESSFULLY_CANCELLED
                        break
                    default:
                        status = CancellationJobStatus.FAILED_TO_CANCEL
                        break
                }
                return {
                    TransformationJobStatus: status,
                } as CancelTransformResponse
            } catch (e: any) {
                const errorMessage = (e as Error).message ?? 'Error in CancelTransformation API call'
                this.logging.log('Error: ' + errorMessage)

                cancelTransformationAttempt += 1
                if (cancelTransformationAttempt >= cancelTransformationMaxAttempts) {
                    this.logging.log(`CancelTransformation failed after ${cancelTransformationMaxAttempts} attempts.`)
                    return {
                        TransformationJobStatus: CancellationJobStatus.FAILED_TO_CANCEL,
                    } as CancelTransformResponse
                }

                const expDelayMs = this.getExpDelayForApiRetryMs(cancelTransformationAttempt)
                this.logging.log(
                    `Attempt ${cancelTransformationAttempt}/${cancelTransformationMaxAttempts} to get transformation plan failed, retry in ${expDelayMs} seconds`
                )
                await this.sleep(expDelayMs * 1000)
            }
        }
    }