Up until now, Trigger.dev only supported the following 3 types of triggers: Events, Webhooks, and Scheduled (e.g. cron/interval).

But sometimes it makes sense to be able to invoke a Job manually, without having to specify an event, especially for cases where you want to get notified when the invoked Job Run is complete.

To specify that a job is manually invokable, you can use the invokeTrigger() function when defining a job:


import { invokeTrigger } from "@trigger.dev/sdk";
import { client } from "@/trigger";
export const exampleJob = client.defineJob({
id: "example-job",
name: "Example job",
version: "1.0.1",
trigger: invokeTrigger({
schema: z.object({
foo: z.string(),
}),
}),
run: async (payload, io, ctx) => {
// do something with the payload
},
});

And then you can invoke the job using the Job.invoke() method:


import { exampleJob } from "./exampleJob";
const jobRun = await exampleJob.invoke(
{ foo: "bar" },
{ callbackUrl: `${process.env.VERCEL_URL}/api/callback` }
);

Which is great but things become really cool when you invoke a job from another job and wait for the invoked job to complete:


import { exampleJob } from "./exampleJob";
client.defineJob({
id: "example-job2",
name: "Example job 2",
version: "1.0.1",
trigger: intervalTrigger({
seconds: 60,
}),
run: async (payload, io, ctx) => {
const runResult = await exampleJob.invokeAndWaitForCompletion("⚡", {
foo: "123",
});
},
});

You can also batch up to 25 invocations at once, and we will run them in parallel and wait for all of them to complete before continuing execution of the current job.


import { exampleJob } from "./exampleJob";
client.defineJob({
id: "example-job2",
name: "Example job 2",
version: "1.0.1",
trigger: intervalTrigger({
seconds: 60,
}),
run: async (payload, io, ctx) => {
const runs = await exampleJob.batchInvokeAndWaitForCompletion("⚡", [
{
payload: {
userId: "123",
tier: "free",
},
},
{
payload: {
userId: "abc",
tier: "paid",
},
},
]);
// runs is an array of RunNotification objects
},
});

See our Invoke Trigger docs for more info. Upgrade to the latest version of the SDK to start using this feature.

How to update

The Trigger.dev Cloud is now running v2.2.4. If you are self-hosting you can upgrade by pinning to the v2.2.4 tag.

The trigger.dev/* packages are now at v2.2.5. You can update using the following command:


npx @trigger.dev/cli@latest update

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now