-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmetadata.ts
More file actions
37 lines (30 loc) · 873 Bytes
/
Copy pathmetadata.ts
File metadata and controls
37 lines (30 loc) · 873 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
import { logger, metadata, task } from "@trigger.dev/sdk";
import { setTimeout } from "node:timers/promises";
export const metadataTestTask = task({
id: "metadata-tester",
retry: {
maxAttempts: 3,
minTimeoutInMs: 500,
maxTimeoutInMs: 1000,
factor: 1.5,
},
run: async (payload: any, { ctx, signal }) => {
let iteration = 0;
while (!signal.aborted) {
await setTimeout(1000);
iteration++;
metadata.set(`test-key-${iteration}`, `test-value-${iteration}`);
metadata.append(`test-keys-${iteration}`, `test-value-${iteration}`);
metadata.increment(`test-counter-${iteration}`, 1);
await setTimeout(1000);
}
logger.info("Run completed", { iteration });
return {
success: true,
};
},
onCancel: async ({ runPromise }) => {
await metadata.flush();
await runPromise;
},
});