1
- import { tasks , runs , TaskOutput , TaskPayload , TaskIdentifier } from "@trigger.dev/sdk/v3" ;
2
- import { createJsonHeroDoc } from "./trigger/simple.js" ;
3
-
4
- type createJsonHeroDocPayload = TaskPayload < typeof createJsonHeroDoc > ; // retrieves the payload type of the task
5
- type createJsonHeroDocOutput = TaskOutput < typeof createJsonHeroDoc > ; // retrieves the output type of the task
6
- type createJsonHeroDocIdentifier = TaskIdentifier < typeof createJsonHeroDoc > ; // retrieves the identifier of the task
1
+ import { tasks } from "@trigger.dev/sdk/v3" ;
7
2
8
3
async function main ( ) {
9
- const anyHandle = await tasks . trigger (
4
+ await tasks . trigger (
10
5
"create-jsonhero-doc" ,
11
6
{
12
7
title : "Hello World" ,
@@ -15,78 +10,22 @@ async function main() {
15
10
} ,
16
11
} ,
17
12
{
18
- delay : "1m" ,
19
13
ttl : "1m" ,
20
14
}
21
15
) ;
22
16
23
- const anyRun = await runs . retrieve ( anyHandle ) ;
24
-
25
- console . log ( `Run ${ anyHandle . id } status: ${ anyRun . status } , ttl: ${ anyRun . ttl } ` , anyRun . output ) ;
26
-
27
- const typedRun = await runs . retrieve < typeof createJsonHeroDoc > ( anyHandle . id ) ;
28
-
29
- console . log ( `Run ${ anyHandle . id } status: ${ typedRun . status } ` , typedRun . output ) ;
30
-
31
- await new Promise ( ( resolve ) => setTimeout ( resolve , 121000 ) ) ; // wait for 2 minutes
32
-
33
- const expiredRun = await runs . retrieve ( anyRun . id ) ;
34
-
35
- console . log (
36
- `Run ${ anyHandle . id } status: ${ expiredRun . status } , expired at: ${ expiredRun . expiredAt } ` ,
37
- expiredRun . output
38
- ) ;
39
-
40
- const handle = await tasks . trigger < typeof createJsonHeroDoc > ( "create-jsonhero-doc" , {
41
- title : "Hello World" ,
42
- content : {
43
- message : "Hello, World!" ,
44
- } ,
45
- } ) ;
46
-
47
- console . log ( handle ) ;
48
-
49
- const typedRetrieveRun = await runs . retrieve ( handle ) ;
50
-
51
- console . log ( `Run ${ handle . id } status: ${ typedRetrieveRun . status } ` , typedRetrieveRun . output ) ;
52
-
53
- const completedRun = await runs . poll ( handle , { pollIntervalMs : 100 } ) ;
54
-
55
- console . log ( `Run ${ handle . id } completed with output:` , completedRun . output ) ;
56
-
57
- const run = await tasks . triggerAndPoll < typeof createJsonHeroDoc > ( "create-jsonhero-doc" , {
58
- title : "Hello World" ,
59
- content : {
60
- message : "Hello, World!" ,
61
- } ,
62
- } ) ;
63
-
64
- console . log ( `Run ${ run . id } completed with output: ` , run . output ) ;
65
-
66
- const batchHandle = await tasks . batchTrigger < typeof createJsonHeroDoc > ( "create-jsonhero-doc" , [
17
+ await tasks . trigger (
18
+ "create-jsonhero-doc" ,
67
19
{
68
- payload : {
69
- title : "Hello World" ,
70
- content : {
71
- message : "Hello, World!" ,
72
- } ,
20
+ title : "Hello World" ,
21
+ content : {
22
+ message : "Hello, World!" ,
73
23
} ,
74
24
} ,
75
25
{
76
- payload : {
77
- title : "Hello World 2" ,
78
- content : {
79
- message : "Hello, World 2!" ,
80
- } ,
81
- } ,
82
- } ,
83
- ] ) ;
84
-
85
- const firstRunHandle = batchHandle . runs [ 0 ] ;
86
-
87
- const run2 = await runs . retrieve ( firstRunHandle ) ;
88
-
89
- console . log ( `Run ${ run2 . id } completed with output: ` , run2 . output ) ;
26
+ ttl : "1m" ,
27
+ }
28
+ ) ;
90
29
}
91
30
92
31
main ( ) . catch ( console . error ) ;
0 commit comments