63 lines
1.4 KiB
Plaintext
63 lines
1.4 KiB
Plaintext
---
|
|
title: "Job"
|
|
description: "Job is used to create and configure a Job"
|
|
---
|
|
|
|
A [Job](/documentation/concepts/jobs) is used to define the [Trigger](/documentation/concepts/triggers), metadata, and what happens when it runs.
|
|
|
|
You can define a job by using the `TriggerClient.defineJob` instance method:
|
|
|
|
<RequestExample>
|
|
|
|
```ts Example
|
|
new Job({
|
|
id: "github-integration-on-issue",
|
|
name: "GitHub Integration - On Issue",
|
|
version: "0.1.0",
|
|
trigger: github.triggers.repo({
|
|
event: events.onIssue,
|
|
owner: "triggerdotdev",
|
|
repo: "empty",
|
|
}),
|
|
run: async (payload, io, ctx) => {
|
|
await io.logger.info("This is a simple log info message");
|
|
return { payload, ctx };
|
|
},
|
|
}).attachToClient(client);
|
|
```
|
|
|
|
```ts notifications
|
|
new Job({
|
|
id: "github-integration-on-issue",
|
|
name: "GitHub Integration - On Issue",
|
|
version: "0.1.0",
|
|
trigger: github.triggers.repo({
|
|
event: events.onIssue,
|
|
owner: "triggerdotdev",
|
|
repo: "empty",
|
|
}),
|
|
onSuccess: async (notification) => {
|
|
console.log("Job succeeded", notification);
|
|
},
|
|
onFailure: async (notification) => {
|
|
console.log("Job failed", notification);
|
|
},
|
|
run: async (payload, io, ctx) => {
|
|
await io.logger.info("This is a simple log info message");
|
|
return { payload, ctx };
|
|
},
|
|
}).attachToClient(client);
|
|
```
|
|
|
|
</RequestExample>
|
|
|
|
# Constructor
|
|
|
|
## Parameters
|
|
|
|
<Snippet file="jobs/options.mdx" />
|
|
|
|
## Returns
|
|
|
|
<ResponseField name="Job instance" type="Job" />
|