Docs maxDuration page now states it’s a required param

This commit is contained in:
James Ritchie
2025-01-29 19:30:25 +00:00
parent 3eede3c339
commit 4e7c55920d
+19 -18
View File
@@ -4,7 +4,24 @@ sidebarTitle: "Max duration"
description: "Set a maximum duration for a task to run."
---
By default tasks can execute indefinitely, which can be great! But you also might want to set a `maxDuration` to prevent a task from running too long. You can set the `maxDuration` for a run in the following ways:
The `maxDuration` parameter sets a maximum compute time limit for tasks. When a task exceeds this duration, it will be automatically stopped. This helps prevent runaway tasks and manage compute resources effectively.
You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden:
```ts /config/trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk/v3";
export default defineConfig({
project: "proj_gtcwttqhhtlasxgfuhxs",
maxDuration: 60, // 60 seconds or 1 minute
});
```
<Note>
The minimum maxDuration is 5 seconds. If you want to avoid timeouts, set this value to a very large number of seconds.
</Note>
You can set the `maxDuration` for a run in the following ways:
- Across all your tasks in the [config](/config/config-file#max-duration)
- On a specific task
@@ -12,7 +29,7 @@ By default tasks can execute indefinitely, which can be great! But you also migh
## How it works
The `maxDuration` is set in seconds, and is compared to the CPU time elapsed since the start of a single execution (which we call attempts) of the task. The CPU time is the time that the task has been actively running on the CPU, and does not include time spent waiting during the following:
The `maxDuration` is set in seconds, and is compared to the CPU time elapsed since the start of a single execution (which we call [attempts](/runs#attempts)) of the task. The CPU time is the time that the task has been actively running on the CPU, and does not include time spent waiting during the following:
- `wait.for` calls
- `triggerAndWait` calls
@@ -38,22 +55,6 @@ The above value will be compared to the `maxDuration` you set. If the task excee
![Max duration error](/runs/max-duration-error.png)
<Note>The minimum maxDuration is 5 seconds. The maximum is ~68 years.</Note>
## Configuring a default max duration
You can set a default `maxDuration` for all tasks in your [config file](/config/config-file#default-machine). This will apply to all tasks unless you override it on a specific task or run.
```ts /config/default-max-duration.ts
import { defineConfig } from "@trigger.dev/sdk/v3";
export default defineConfig({
//Your project ref (you can see it on the Project settings page in the dashboard)
project: "proj_gtcwttqhhtlasxgfuhxs",
maxDuration: 60, // 60 seconds or 1 minute
});
```
## Configuring for a task
You can set a `maxDuration` on a specific task: