@@ -5,14 +5,12 @@ description: "Job is used to create and configure a Job"
5
5
6
6
A [ Job] ( /documentation/concepts/jobs ) is used to define the [ Trigger] ( /documentation/concepts/triggers ) , metadata, and what happens when it runs.
7
7
8
- By far the most important thing to understand is the constructor.
9
-
10
- # Constructor
8
+ You can define a job in one of two ways, using the ` new Job ` constructor or by using the ` TriggerClient.defineJob ` instance method.
11
9
12
10
<RequestExample >
13
11
14
- ``` ts cronTrigger
15
- client . defineJob ( {
12
+ ``` ts constructor
13
+ new Job ( client , {
16
14
id: " slack-kpi-summary" ,
17
15
name: " Slack kpi summary" ,
18
16
version: " 0.1.1" ,
@@ -34,7 +32,7 @@ client.defineJob({
34
32
});
35
33
```
36
34
37
- ``` ts webhook
35
+ ``` ts client.defineJob
38
36
client .defineJob ({
39
37
id: " github-integration-on-issue" ,
40
38
name: " GitHub Integration - On Issue" ,
@@ -51,38 +49,31 @@ client.defineJob({
51
49
});
52
50
```
53
51
54
- ``` ts event
52
+ ``` ts queue options
55
53
client .defineJob ({
56
- id: " openai-joke" ,
57
- name: " OpenAI Joke" ,
58
- version: " 0.0.1" ,
59
- trigger: eventTrigger ({
60
- name: " openai.joke" ,
61
- schema: z .object ({
62
- jokePrompt: z .string (),
63
- }),
54
+ id: " github-integration-on-issue" ,
55
+ name: " GitHub Integration - On Issue" ,
56
+ version: " 0.1.0" ,
57
+ trigger: github .triggers .repo ({
58
+ event: events .onIssue ,
59
+ owner: " triggerdotdev" ,
60
+ repo: " empty" ,
64
61
}),
65
- integrations: {
66
- openai ,
62
+ queue: {
63
+ name: " my-queue" ,
64
+ maxConcurrent: 10 , // only 10 runs can happen at the same time
67
65
},
68
66
run : async (payload , io , ctx ) => {
69
- const joke = await io .openai .backgroundCreateChatCompletion (" generate-jokes" , {
70
- model: " gpt-3.5-turbo" ,
71
- messages: [
72
- {
73
- role: " user" ,
74
- content: payload .jokePrompt ,
75
- },
76
- ],
77
- });
78
-
79
- return joke .choices ;
67
+ await io .logger .info (" This is a simple log info message" );
68
+ return { payload , ctx };
80
69
},
81
70
});
82
71
```
83
72
84
73
</RequestExample >
85
74
75
+ # Constructor
76
+
86
77
## Parameters
87
78
88
79
<ParamField body = " client" type = " object" required >
0 commit comments