Skip to content

Commit 3ccc035

Browse files
authored
waitForTask: switch from polling every 5s to an incremental 2s, 3s, 4.5s, 6.75s, ~10s... progression (#3738)
optimizes for tasks finishing early by trying more often in the beginning, but also ends up waiting longer for long-running tasks this takes the default waitForTask max wait from $`5 * 10 = 50s`$, to $` \displaystyle\sum_{n=1}^{10} 2 * 1.5^n \approx 226s `$. Related to AAH-2347 No-Issue
1 parent 3d94d8b commit 3ccc035

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/utilities/wait-for-task.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { parsePulpIDFromURL } from './parse-pulp-id';
44

55
interface Options {
66
bailAfter?: number;
7+
multiplier?: number;
78
waitMs?: number;
89
}
910

1011
export function waitForTask(task, options: Options = {}) {
11-
// default to 5s wait with max 10 attempts
12-
const { waitMs = 5000, bailAfter = 10 } = options;
12+
// default to starting with a 2s wait, increasing the wait time 1.5x each time, with max 10 attempts
13+
// 2000, 1.5, 10 = ~226s ; 500, 1.5, 10 = ~57s
14+
const { waitMs = 2000, multiplier = 1.5, bailAfter = 10 } = options;
1315

1416
return TaskAPI.get(task).then((result) => {
1517
const failing = ['skipped', 'failed', 'canceled'];
@@ -28,7 +30,11 @@ export function waitForTask(task, options: Options = {}) {
2830
}
2931

3032
return new Promise((r) => setTimeout(r, waitMs)).then(() =>
31-
waitForTask(task, { ...options, bailAfter: bailAfter - 1 }),
33+
waitForTask(task, {
34+
...options,
35+
waitMs: Math.round(waitMs * multiplier),
36+
bailAfter: bailAfter - 1,
37+
}),
3238
);
3339
}
3440
});

0 commit comments

Comments
 (0)