Skip to content

Commit 9e9c692

Browse files
D-40783 Enhanced waitForTask function
1 parent ef5d54d commit 9e9c692

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

dist/index.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65237,14 +65237,33 @@ class DeployManager {
6523765237
// Wait for task to complete
6523865238
static async waitForTask(taskId) {
6523965239
const runningStates = ["QUEUED", "EXECUTING", "ABORTING", "STOPPING", "FAILING", "PENDING"];
65240-
let task = await this.getDeploymentTask(taskId);
65241-
65242-
while (runningStates.indexOf(task.state) > -1) {
65240+
const maxTransientRetries = 5;
65241+
let transientAttempts = 0;
65242+
let task;
65243+
while (true) {
65244+
try {
65245+
task = await this.getDeploymentTask(taskId);
65246+
// If it's no longer in a running state, we're done
65247+
if (!runningStates.includes(task.state)) {
65248+
return task.state;
65249+
}
65250+
// Reset transient counter on a successful fetch
65251+
transientAttempts = 0;
65252+
} catch (error) {
65253+
// Handle the specific 500 “cannot create children…” error as transient
65254+
const msg = error.message || "";
65255+
if (msg.includes("500") && msg.includes("cannot create children while terminating or terminated") && transientAttempts < maxTransientRetries) {
65256+
transientAttempts++;
65257+
console.log(`Transient error checking task status (attempt ${transientAttempts}/${maxTransientRetries}): ${msg} Retrying in ${transientAttempts * 5}s…`);
65258+
await this.sleepFor(transientAttempts * 5);
65259+
continue;
65260+
}
65261+
// For any other error (or too many retries), rethrow
65262+
throw error;
65263+
}
65264+
// Wait before the next status check
6524365265
await this.sleepFor(5);
65244-
task = await this.getDeploymentTask(taskId);
6524565266
}
65246-
65247-
return task.state;
6524865267
}
6524965268

6525065269
// Archive deployment task

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/deploy-manager.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,33 @@ class DeployManager {
302302
// Wait for task to complete
303303
static async waitForTask(taskId) {
304304
const runningStates = ["QUEUED", "EXECUTING", "ABORTING", "STOPPING", "FAILING", "PENDING"];
305-
let task = await this.getDeploymentTask(taskId);
306-
307-
while (runningStates.indexOf(task.state) > -1) {
305+
const maxTransientRetries = 5;
306+
let transientAttempts = 0;
307+
let task;
308+
while (true) {
309+
try {
310+
task = await this.getDeploymentTask(taskId);
311+
// If it's no longer in a running state, we're done
312+
if (!runningStates.includes(task.state)) {
313+
return task.state;
314+
}
315+
// Reset transient counter on a successful fetch
316+
transientAttempts = 0;
317+
} catch (error) {
318+
// Handle the specific 500 “cannot create children…” error as transient
319+
const msg = error.message || "";
320+
if (msg.includes("500") && msg.includes("cannot create children while terminating or terminated") && transientAttempts < maxTransientRetries) {
321+
transientAttempts++;
322+
console.log(`Transient error checking task status (attempt ${transientAttempts}/${maxTransientRetries}): ${msg} Retrying in ${transientAttempts * 5}s…`);
323+
await this.sleepFor(transientAttempts * 5);
324+
continue;
325+
}
326+
// For any other error (or too many retries), rethrow
327+
throw error;
328+
}
329+
// Wait before the next status check
308330
await this.sleepFor(5);
309-
task = await this.getDeploymentTask(taskId);
310331
}
311-
312-
return task.state;
313332
}
314333

315334
// Archive deployment task

0 commit comments

Comments
 (0)