SDK
invokeTrigger()
Getting Started
Concepts
Guides
- Frameworks
- Using the CLI
- Manual setup
- Running your Jobs
- Managing Jobs
- Using the Dashboard
- Using Integrations
- React hooks
- Deployment
- Event Filters
- Zod
- Self hosting
- Contributing
Overview
- Introduction
- Create an Integration
Integrations
SDK
HTTP Reference
Overview
SDK
invokeTrigger()
Use invokeTrigger()
to allow a Job to be manually triggered using Job.invoke()
//this Job subscribes to an event called new.user
export const exampleJob = client.defineJob({
id: "example-job",
name: "Example job",
version: "1.0.1",
trigger: invokeTrigger({
//the expected payload shape
schema: z.object({
userId: z.string(),
tier: z.union([z.literal("free"), z.literal("pro")]),
}),
//(optional) example payload object
examples: [
{
id: "issue.opened",
name: "Issue opened",
payload: {
userId: "1234",
tier: "free",
},
//optional
icon: "github",
},
],
}),
run: async (payload, io, ctx) => {
// do something with the payload
},
});
These are the docs for Trigger.dev v2 which will be deprecated on January 31st, 2025. You probably want the v3 docs.
Setting invokeTrigger()
on a job allows you to manually trigger the job using Job.invoke()
, either from your backend or from inside another job. See our Invoke Trigger guide for more info.
Parameters
A Zod schema that defines the shape of the
job payload. The default is z.any()
which is any
. This will be used to correctly type the Job.invoke()
method.
Used to provide example payloads that are accepted by the job.
This will be available in the dashboard and can be used to trigger test runs.
//this Job subscribes to an event called new.user
export const exampleJob = client.defineJob({
id: "example-job",
name: "Example job",
version: "1.0.1",
trigger: invokeTrigger({
//the expected payload shape
schema: z.object({
userId: z.string(),
tier: z.union([z.literal("free"), z.literal("pro")]),
}),
//(optional) example payload object
examples: [
{
id: "issue.opened",
name: "Issue opened",
payload: {
userId: "1234",
tier: "free",
},
//optional
icon: "github",
},
],
}),
run: async (payload, io, ctx) => {
// do something with the payload
},
});
Was this page helpful?
//this Job subscribes to an event called new.user
export const exampleJob = client.defineJob({
id: "example-job",
name: "Example job",
version: "1.0.1",
trigger: invokeTrigger({
//the expected payload shape
schema: z.object({
userId: z.string(),
tier: z.union([z.literal("free"), z.literal("pro")]),
}),
//(optional) example payload object
examples: [
{
id: "issue.opened",
name: "Issue opened",
payload: {
userId: "1234",
tier: "free",
},
//optional
icon: "github",
},
],
}),
run: async (payload, io, ctx) => {
// do something with the payload
},
});