756024da78
* Add support for Run Notifications #401 * Fixed typo and added changeset
59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
---
|
|
title: "defineJob()"
|
|
description: "Defines a job"
|
|
---
|
|
|
|
A [Job](/documentation/concepts/jobs) is used to define the [Trigger](/documentation/concepts/triggers), metadata, and what happens when it runs.
|
|
|
|
<RequestExample>
|
|
|
|
```ts example
|
|
client.defineJob({
|
|
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 };
|
|
},
|
|
});
|
|
```
|
|
|
|
```ts notifications
|
|
client.defineJob({
|
|
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 };
|
|
},
|
|
});
|
|
```
|
|
|
|
</RequestExample>
|
|
|
|
## Parameters
|
|
|
|
<Snippet file="jobs/options.mdx" />
|
|
|
|
## Returns
|
|
|
|
<ResponseField name="Job instance" type="Job" />
|