-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathattemptFailures.ts
More file actions
50 lines (43 loc) · 1.01 KB
/
attemptFailures.ts
File metadata and controls
50 lines (43 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { task } from "@trigger.dev/sdk";
import { setTimeout } from "timers/promises";
export const attemptFailures = task({
id: "attempt-failures",
retry: {
maxAttempts: 3,
minTimeoutInMs: 500,
maxTimeoutInMs: 1000,
factor: 1.5,
},
run: async (payload: any, { ctx }) => {
await setTimeout(5);
await attemptFailureSubtask.triggerAndWait({}).unwrap();
},
});
export const attemptFailureSubtask = task({
id: "attempt-failure-subtask",
retry: {
maxAttempts: 1,
},
run: async (payload: any, { ctx }) => {
await setTimeout(20_000);
throw new Error("Forced error to cause a retry");
},
});
export const attemptFailures2 = task({
id: "attempt-failures-2",
retry: {
maxAttempts: 3,
minTimeoutInMs: 500,
maxTimeoutInMs: 1000,
factor: 1.5,
},
run: async (payload: any, { ctx }) => {
if (ctx.attempt.number <= 2) {
throw new Error("Forced error to cause a retry");
}
await setTimeout(10_000);
return {
success: true,
};
},
});