-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathbatches.ts
More file actions
39 lines (33 loc) · 934 Bytes
/
batches.ts
File metadata and controls
39 lines (33 loc) · 934 Bytes
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
import { task } from "@trigger.dev/sdk/v3";
import { setTimeout } from "timers/promises";
export const batchTriggerAndWait = task({
id: "batch-trigger-and-wait",
maxDuration: 60,
run: async (payload: { count: number }, { ctx }) => {
const payloads = Array.from({ length: payload.count }, (_, i) => ({
payload: { waitSeconds: 1, output: `test${i}` },
}));
// First batch triggerAndWait with idempotency keys
const firstResults = await fixedLengthTask.batchTriggerAndWait(payloads);
},
});
type Payload = {
waitSeconds: number;
error?: string;
output?: any;
};
export const fixedLengthTask = task({
id: "fixed-length-lask",
retry: {
maxAttempts: 2,
maxTimeoutInMs: 100,
},
machine: "micro",
run: async ({ waitSeconds = 1, error, output }: Payload) => {
await setTimeout(waitSeconds * 1000);
if (error) {
throw new Error(error);
}
return output;
},
});