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
description: "Set a maximum duration for a task to run."
2
+
title: "Max compute time"
3
+
sidebarTitle: "Max compute time"
4
+
description: "Set a maximum compute time limit for a task to run."
5
5
---
6
6
7
-
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.
7
+
The `maxComputeSeconds` 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.
8
8
9
-
You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden:
9
+
<Note>
10
+
`maxComputeSeconds` replaces the deprecated `maxComputeSeconds` parameter. Both work the same way, but we recommend using `maxComputeSeconds` for clarity.
11
+
</Note>
12
+
13
+
You must set a default maxComputeSeconds in your `trigger.config.ts` file, which will apply to all tasks unless overridden:
10
14
11
15
```ts /config/trigger.config.ts
12
16
import { defineConfig } from"@trigger.dev/sdk";
13
17
14
18
exportdefaultdefineConfig({
15
19
project: "proj_gtcwttqhhtlasxgfuhxs",
16
-
maxDuration: 60, // 60 seconds or 1 minute
20
+
maxComputeSeconds: 60, // 60 seconds or 1 minute
17
21
});
18
22
```
19
23
20
24
<Note>
21
-
The minimum maxDuration is 5 seconds. If you want to avoid timeouts, set this value to a very large number of seconds.
25
+
The minimum maxComputeSeconds is 5 seconds. If you want to avoid timeouts, set this value to a very large number of seconds.
22
26
</Note>
23
27
24
-
You can set the `maxDuration` for a run in the following ways:
28
+
You can set the `maxComputeSeconds` for a run in the following ways:
25
29
26
-
- Across all your tasks in the [config](/config/config-file#max-duration)
30
+
- Across all your tasks in the [config](/config/config-file#max-compute-time)
27
31
- On a specific task
28
-
- On a specific run when you [trigger a task](/triggering#maxduration)
32
+
- On a specific run when you [trigger a task](/triggering#maxcomputeseconds)
29
33
30
34
## How it works
31
35
32
-
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:
36
+
The `maxComputeSeconds` 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:
33
37
34
38
-`wait.for` calls
35
39
-`triggerAndWait` calls
@@ -40,9 +44,9 @@ You can inspect the CPU time of a task inside the run function with our `usage`
40
44
```ts /trigger/max-duration.ts
41
45
import { task, usage } from"@trigger.dev/sdk";
42
46
43
-
exportconstmaxDurationTask=task({
47
+
exportconstmaxComputeSecondsTask=task({
44
48
id: "max-duration-task",
45
-
maxDuration: 300, // 300 seconds or 5 minutes
49
+
maxComputeSeconds: 300, // 300 seconds or 5 minutes
The above value will be compared to the `maxDuration` you set. If the task exceeds the `maxDuration`, it will be stopped with the following error:
58
+
The above value will be compared to the `maxComputeSeconds` you set. If the task exceeds the `maxComputeSeconds`, it will be stopped with the following error:
You can set a `maxComputeSeconds` on a specific task:
61
65
62
66
```ts /trigger/max-duration-task.ts
63
67
import { task } from"@trigger.dev/sdk";
64
68
65
-
exportconstmaxDurationTask=task({
69
+
exportconstmaxComputeSecondsTask=task({
66
70
id: "max-duration-task",
67
-
maxDuration: 300, // 300 seconds or 5 minutes
71
+
maxComputeSeconds: 300, // 300 seconds or 5 minutes
68
72
run: async (payload:any, { ctx }) => {
69
73
//...
70
74
},
71
75
});
72
76
```
73
77
74
-
This will override the default `maxDuration` set in the config file. If you have a config file with a default `maxDuration` of 60 seconds, and you set a `maxDuration` of 300 seconds on a task, the task will run for 300 seconds.
78
+
This will override the default `maxComputeSeconds` set in the config file. If you have a config file with a default `maxComputeSeconds` of 60 seconds, and you set a `maxComputeSeconds` of 300 seconds on a task, the task will run for 300 seconds.
75
79
76
80
You can "turn off" the Max duration set in your config file for a specific task like so:
77
81
78
82
```ts /trigger/max-duration-task.ts
79
83
import { task, timeout } from"@trigger.dev/sdk";
80
84
81
-
exportconstmaxDurationTask=task({
85
+
exportconstmaxComputeSecondsTask=task({
82
86
id: "max-duration-task",
83
-
maxDuration: timeout.None, // No max duration
87
+
maxComputeSeconds: timeout.None, // No max duration
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` on a task, and all runs of that task will be stopped if they exceed the duration.
125
+
By default tasks can execute indefinitely, which can be great! But you also might want to set a `maxComputeSeconds` to prevent a task from running too long. You can set the `maxComputeSeconds` on a task, and all runs of that task will be stopped if they exceed the duration.
126
126
127
127
```ts /trigger/long-task.ts
128
128
exportconst longTask =task({
129
129
id: "long-task",
130
-
maxDuration: 300, // 300 seconds or 5 minutes
130
+
maxComputeSeconds: 300, // 300 seconds or 5 minutes
131
131
run: async (payload:any, { ctx }) => {
132
132
//...
133
133
},
134
134
});
135
135
```
136
136
137
-
See our [maxDuration guide](/runs/max-duration) for more information.
137
+
See our [maxComputeSeconds guide](/runs/max-duration) for more information.
Copy file name to clipboardExpand all lines: docs/triggering.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -932,7 +932,7 @@ Without `maxDelay`, continuous triggers would prevent the run from ever executin
932
932
933
933
By default, debounce uses **leading mode** - the run executes with data from the **first** trigger.
934
934
935
-
With **trailing mode**, each subsequent trigger updates the run's data (payload, metadata, tags, maxAttempts, maxDuration, and machine), so the run executes with data from the **last** trigger:
935
+
With **trailing mode**, each subsequent trigger updates the run's data (payload, metadata, tags, maxAttempts, maxComputeSeconds, and machine), so the run executes with data from the **last** trigger:
936
936
937
937
```ts
938
938
// Leading mode (default): runs with first payload
@@ -1090,9 +1090,9 @@ View our [tags doc](/tags) for more information.
1090
1090
1091
1091
View our [metadata doc](/runs/metadata) for more information.
1092
1092
1093
-
### `maxDuration`
1093
+
### `maxComputeSeconds`
1094
1094
1095
-
View our [maxDuration doc](/runs/max-duration) for more information.
1095
+
View our [maxComputeSeconds doc](/runs/max-duration) for more information.
0 commit comments