You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tasks/overview.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ See our [maxDuration guide](/runs/max-duration) for more information.
142
142
143
143
You can register global lifecycle hooks that are executed for all runs, regardless of the task. While you can still define these in the `trigger.config.ts` file, you can also register them anywhere in your codebase:
You can access the database client using `getDb()` in your tasks `run` function and all your hooks (global or task specific):
238
238
239
-
```ts
239
+
```typescript
240
240
import { getDb } from"./db";
241
241
242
242
exportconst myTask =task({
@@ -251,7 +251,7 @@ export const myTask = task({
251
251
252
252
You can also define middleware per task by passing the `middleware` option in the task definition. This runs after global middleware and before the `run` function. Use it when only specific tasks need certain locals or setup:
These lifecycle hooks allow you to run code when a run is paused or resumed because of a wait:
321
321
322
-
```ts
322
+
```typescript
323
323
exportconst myTask =task({
324
324
id: "my-task",
325
325
onWait: async ({ wait }) => {
@@ -462,15 +462,15 @@ Read more about `catchError` in our [Errors and Retrying guide](/errors-retrying
462
462
463
463
You can define an `onCancel` hook that is called when a run is cancelled. This is useful if you want to clean up any resources that were allocated for the run.
464
464
465
-
```ts
465
+
```typescript
466
466
tasks.onCancel(({ ctx, signal }) => {
467
467
console.log("Run cancelled", signal);
468
468
});
469
469
```
470
470
471
471
You can use the `onCancel` hook along with the `signal` passed into the run function to interrupt a call to an external service, for example using the [streamText](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) function from the AI SDK:
0 commit comments