Skip to content

Commit da7ba7e

Browse files
author
David Hasani
committed
use 3 retries
1 parent 0e6fd9f commit da7ba7e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,17 @@ export async function uploadArtifactToS3(
112112

113113
let response = undefined
114114
/* The existing S3 client has built-in retries but it requires the bucket name, so until
115-
* CreateUploadUrl can be modified to return the S3 bucket name, manually implement retries
115+
* CreateUploadUrl can be modified to return the S3 bucket name, manually implement retries.
116+
* Alternatively, when waitUntil supports a fixed number of retries and retriableCodes, use that.
116117
*/
117118
const retriableCodes = [408, 429, 500, 502, 503, 504]
118-
for (let i = 0; i < 3; i++) {
119+
for (let i = 0; i < 4; i++) {
119120
try {
120121
response = await request.fetch('PUT', resp.uploadUrl, {
121122
body: buffer,
122123
headers: getHeadersObj(sha256, resp.kmsKeyArn),
123124
}).response
124-
getLogger().info(`CodeTransformation: upload to S3 status on attempt ${i + 1}/3 = ${response.status}`)
125+
getLogger().info(`CodeTransformation: upload to S3 status on attempt ${i + 1}/4 = ${response.status}`)
125126
if (response.status === 200) {
126127
break
127128
}
@@ -130,13 +131,13 @@ export async function uploadArtifactToS3(
130131
if (response && !retriableCodes.includes(response.status)) {
131132
throw new Error(`Upload failed with status code = ${response.status}; did not automatically retry`)
132133
}
133-
if (i !== 2) {
134+
if (i !== 3) {
134135
await sleep(1000 * Math.pow(2, i))
135136
}
136137
}
137138
}
138139
if (!response || response.status !== 200) {
139-
const uploadFailedError = `Upload failed after up to 3 attempts with status code = ${response?.status ?? 'unavailable'}`
140+
const uploadFailedError = `Upload failed after up to 4 attempts with status code = ${response?.status ?? 'unavailable'}`
140141
getLogger().error(`CodeTransformation: ${uploadFailedError}`)
141142
throw new Error(uploadFailedError)
142143
}

packages/core/src/test/codewhisperer/commands/transformByQ.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,15 @@ describe('transformByQ', function () {
511511
sinon.assert.calledTwice(fetchStub)
512512
})
513513

514-
it('should throw error after 3 failed upload attempts', async () => {
514+
it('should throw error after 4 failed upload attempts', async () => {
515515
const failedResponse = {
516516
ok: false,
517517
status: 500,
518518
text: () => Promise.resolve('Internal Server Error'),
519519
}
520520
fetchStub.returns({ response: Promise.resolve(failedResponse) })
521521
const expectedMessage =
522-
'The upload failed due to: Upload failed after up to 3 attempts with status code = 500. For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/troubleshooting-code-transformation.html#project-upload-fail)'
522+
'The upload failed due to: Upload failed after up to 4 attempts with status code = 500. For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/troubleshooting-code-transformation.html#project-upload-fail)'
523523
await assert.rejects(
524524
uploadArtifactToS3(
525525
'test.zip',

0 commit comments

Comments
 (0)