diff --git a/docs/config/config-file.mdx b/docs/config/config-file.mdx index d11704d303..ef79bc8620 100644 --- a/docs/config/config-file.mdx +++ b/docs/config/config-file.mdx @@ -99,16 +99,16 @@ import { defineConfig } from "@trigger.dev/sdk"; export default defineConfig({ project: "", // Your other config settings... - onSuccess: async (payload, output, { ctx }) => { + onSuccess: async ({ payload, output, ctx }) => { console.log("Task succeeded", ctx.task.id); }, - onFailure: async (payload, error, { ctx }) => { + onFailure: async ({ payload, error, ctx }) => { console.log("Task failed", ctx.task.id); }, - onStart: async (payload, { ctx }) => { + onStart: async ({ payload, ctx }) => { console.log("Task started", ctx.task.id); }, - init: async (payload, { ctx }) => { + init: async ({ payload, ctx }) => { console.log("I run before any task is run"); }, }); diff --git a/docs/errors-retrying.mdx b/docs/errors-retrying.mdx index 7bd2deae3c..246db2b82a 100644 --- a/docs/errors-retrying.mdx +++ b/docs/errors-retrying.mdx @@ -180,7 +180,7 @@ export const taskWithFetchRetries = task({ ## Advanced error handling and retrying -We provide a `handleError` callback on the task and in your `trigger.config` file. This gets called when an uncaught error is thrown in your task. +We provide a `catchError` callback on the task and in your `trigger.config` file. This gets called when an uncaught error is thrown in your task. You can @@ -219,7 +219,7 @@ export const openaiTask = task({ return chatCompletion.choices[0].message.content; }, - handleError: async (payload, error, { ctx, retryAt }) => { + catchError: async ({ payload, error, ctx, retryAt }) => { if (error instanceof OpenAI.APIError) { if (!error.status) { return { diff --git a/docs/migrating-from-v3.mdx b/docs/migrating-from-v3.mdx index e06cd08064..03f0cae577 100644 --- a/docs/migrating-from-v3.mdx +++ b/docs/migrating-from-v3.mdx @@ -232,7 +232,7 @@ import { task } from "@trigger.dev/sdk"; export const myTask = task({ id: "my-task", - onStart: (payload, { ctx }) => {}, + onStart: ({ payload, ctx }) => {}, run: async (payload, { ctx }) => {}, }); ``` diff --git a/docs/tasks/overview.mdx b/docs/tasks/overview.mdx index aa305f2f80..2b3452c87a 100644 --- a/docs/tasks/overview.mdx +++ b/docs/tasks/overview.mdx @@ -181,7 +181,7 @@ This function is called before a run attempt: ```ts /trigger/init.ts export const taskWithInit = task({ id: "task-with-init", - init: async (payload, { ctx }) => { + init: async ({ payload, ctx }) => { //... }, run: async (payload: any, { ctx }) => { @@ -195,7 +195,7 @@ You can also return data from the `init` function that will be available in the ```ts /trigger/init-return.ts export const taskWithInitReturn = task({ id: "task-with-init-return", - init: async (payload, { ctx }) => { + init: async ({ payload, ctx }) => { return { someData: "someValue" }; }, run: async (payload: any, { ctx, init }) => { @@ -213,7 +213,7 @@ This function is called after the `run` function is executed, regardless of whet ```ts /trigger/cleanup.ts export const taskWithCleanup = task({ id: "task-with-cleanup", - cleanup: async (payload, { ctx }) => { + cleanup: async ({ payload, ctx }) => { //... }, run: async (payload: any, { ctx }) => { @@ -230,7 +230,7 @@ Our task middleware system runs at the top level, executing before and after all An error thrown in `middleware` is just like an uncaught error in the run function: it will - propagate through to `handleError()` and then will fail the attempt (causing a retry). + propagate through to `catchError()` function and then will fail the attempt (causing a retry). The `locals` API allows you to share data between middleware and hooks. @@ -303,7 +303,7 @@ When a task run starts, the `onStart` function is called. It's useful for sendin ```ts /trigger/on-start.ts export const taskWithOnStart = task({ id: "task-with-on-start", - onStart: async (payload, { ctx }) => { + onStart: async ({ payload, ctx }) => { //... }, run: async (payload: any, { ctx }) => { @@ -319,7 +319,7 @@ import { defineConfig } from "@trigger.dev/sdk"; export default defineConfig({ project: "proj_1234", - onStart: async (payload, { ctx }) => { + onStart: async ({ payload, ctx }) => { console.log("Task started", ctx.task.id); }, }); @@ -357,7 +357,7 @@ When a task run succeeds, the `onSuccess` function is called. It's useful for se ```ts /trigger/on-success.ts export const taskWithOnSuccess = task({ id: "task-with-on-success", - onSuccess: async (payload, output, { ctx }) => { + onSuccess: async ({ payload, output, ctx }) => { //... }, run: async (payload: any, { ctx }) => { @@ -373,7 +373,7 @@ import { defineConfig } from "@trigger.dev/sdk"; export default defineConfig({ project: "proj_1234", - onSuccess: async (payload, output, { ctx }) => { + onSuccess: async ({ payload, output, ctx }) => { console.log("Task succeeded", ctx.task.id); }, }); @@ -388,7 +388,7 @@ This hook is executed when a run completes, regardless of whether it succeeded o ```ts /trigger/on-complete.ts export const taskWithOnComplete = task({ id: "task-with-on-complete", - onComplete: async (payload, output, { ctx }) => { + onComplete: async ({ payload, output, ctx }) => { if (result.ok) { console.log("Run succeeded", result.data); } else { @@ -404,7 +404,7 @@ When a task run fails, the `onFailure` function is called. It's useful for sendi ```ts /trigger/on-failure.ts export const taskWithOnFailure = task({ id: "task-with-on-failure", - onFailure: async (payload, error, { ctx }) => { + onFailure: async ({ payload, error, ctx }) => { //... }, run: async (payload: any, { ctx }) => { @@ -420,7 +420,7 @@ import { defineConfig } from "@trigger.dev/sdk"; export default defineConfig({ project: "proj_1234", - onFailure: async (payload, error, { ctx }) => { + onFailure: async ({ payload, error, ctx }) => { console.log("Task failed", ctx.task.id); }, }); @@ -429,14 +429,15 @@ export default defineConfig({ Errors thrown in the `onFailure` function are ignored. - `onFailure` doesn’t fire for some of the run statuses like `Crashed`, `System failures`, and `Canceled`. + `onFailure` doesn’t fire for some of the run statuses like `Crashed`, `System failures`, and + `Canceled`. -### `handleError` functions +### `catchError` functions You can define a function that will be called when an error is thrown in the `run` function, that allows you to control how the error is handled and whether the task should be retried. -Read more about `handleError` in our [Errors and Retrying guide](/errors-retrying). +Read more about `catchError` in our [Errors and Retrying guide](/errors-retrying). Uncaught errors will throw a special internal error of the type `HANDLE_ERROR_ERROR`.