Task API
task#
Defines a task with an ID and an async run function.
import { task } from "@trigger.dev/sdk";
export const helloWorld = task({
id: "hello-world",
run: async (payload: { message: string }) => payload.message,
});Output: a task definition that returns the payload message when executed.
trigger#
Starts a task run and returns a handle.
const handle = await helloWorld.trigger({ message: "Hello world!" });
console.log(handle.id);Output: a run handle with an ID.
retry#
Configures retry attempts and backoff for a task.
retry: {
maxAttempts: 3,
minTimeoutInMs: 1000,
maxTimeoutInMs: 5000,
factor: 2,
randomize: true,
}Output: failed attempts follow the configured retry policy.