-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
maxComputeSeconds #3167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
maxComputeSeconds #3167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@trigger.dev/core": patch | ||
| "@trigger.dev/sdk": patch | ||
| "trigger.dev": patch | ||
| --- | ||
|
|
||
| Deprecate `maxDuration` in favor of `maxComputeSeconds` because it's clearer. The new `maxComputeSeconds` property better reflects that the limit is based on compute time (CPU time) rather than wall-clock time. The old `maxDuration` property is still supported for backwards compatibility but will show deprecation warnings. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,39 @@ | ||
| --- | ||
| title: "Max duration" | ||
| sidebarTitle: "Max duration" | ||
| description: "Set a maximum duration for a task to run." | ||
| title: "Max compute time" | ||
| sidebarTitle: "Max compute time" | ||
| description: "Set a maximum compute time limit for a task to run." | ||
| --- | ||
|
|
||
| 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. | ||
| 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. | ||
|
|
||
| You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden: | ||
| <Note> | ||
| `maxDuration` replaces the deprecated `maxComputeSeconds` parameter. Both work the same way, but we recommend using `maxDuration` for clarity. | ||
| </Note> | ||
matt-aitken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| You must set a default maxComputeSeconds in your `trigger.config.ts` file, which will apply to all tasks unless overridden: | ||
|
|
||
| ```ts /config/trigger.config.ts | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use These fences use Proposed fix-```ts /config/trigger.config.ts
+```typescript /config/trigger.config.ts
@@
-```ts /trigger/max-duration.ts
+```typescript /trigger/max-duration.ts
@@
-```ts /trigger/max-duration-task.ts
+```typescript /trigger/max-duration-task.ts
@@
-```ts /trigger/max-duration-task.ts
+```typescript /trigger/max-duration-task.ts
@@
-```ts /trigger/max-duration.ts
+```typescript /trigger/max-duration.ts
@@
-```ts /trigger/max-duration.ts
+```typescript /trigger/max-duration.ts
@@
-```ts /trigger/max-duration-task.ts
+```typescript /trigger/max-duration-task.tsAs per coding guidelines, Also applies to: 44-44, 66-66, 82-82, 98-98, 112-112, 129-129 🤖 Prompt for AI Agents |
||
| import { defineConfig } from "@trigger.dev/sdk"; | ||
|
|
||
| export default defineConfig({ | ||
| project: "proj_gtcwttqhhtlasxgfuhxs", | ||
| maxDuration: 60, // 60 seconds or 1 minute | ||
| maxComputeSeconds: 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. | ||
| The minimum maxComputeSeconds 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: | ||
| You can set the `maxComputeSeconds` for a run in the following ways: | ||
|
|
||
| - Across all your tasks in the [config](/config/config-file#max-duration) | ||
| - Across all your tasks in the [config](/config/config-file#max-compute-time) | ||
| - On a specific task | ||
| - On a specific run when you [trigger a task](/triggering#maxduration) | ||
| - On a specific run when you [trigger a task](/triggering#maxcomputeseconds) | ||
|
|
||
| ## 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](/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: | ||
| 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: | ||
|
|
||
| - `wait.for` calls | ||
| - `triggerAndWait` calls | ||
|
|
@@ -40,9 +44,9 @@ You can inspect the CPU time of a task inside the run function with our `usage` | |
| ```ts /trigger/max-duration.ts | ||
| import { task, usage } from "@trigger.dev/sdk"; | ||
|
|
||
| export const maxDurationTask = task({ | ||
| export const maxComputeSecondsTask = task({ | ||
| id: "max-duration-task", | ||
| maxDuration: 300, // 300 seconds or 5 minutes | ||
| maxComputeSeconds: 300, // 300 seconds or 5 minutes | ||
| run: async (payload: any, { ctx }) => { | ||
| let currentUsage = usage.getCurrent(); | ||
|
|
||
|
|
@@ -51,36 +55,36 @@ export const maxDurationTask = task({ | |
| }); | ||
| ``` | ||
|
|
||
| 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: | ||
| 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: | ||
|
|
||
|  | ||
|
|
||
| ## Configuring for a task | ||
|
|
||
| You can set a `maxDuration` on a specific task: | ||
| You can set a `maxComputeSeconds` on a specific task: | ||
|
|
||
| ```ts /trigger/max-duration-task.ts | ||
| import { task } from "@trigger.dev/sdk"; | ||
|
|
||
| export const maxDurationTask = task({ | ||
| export const maxComputeSecondsTask = task({ | ||
| id: "max-duration-task", | ||
| maxDuration: 300, // 300 seconds or 5 minutes | ||
| maxComputeSeconds: 300, // 300 seconds or 5 minutes | ||
| run: async (payload: any, { ctx }) => { | ||
| //... | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| 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. | ||
| 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. | ||
|
|
||
| You can "turn off" the Max duration set in your config file for a specific task like so: | ||
|
|
||
| ```ts /trigger/max-duration-task.ts | ||
| import { task, timeout } from "@trigger.dev/sdk"; | ||
|
|
||
| export const maxDurationTask = task({ | ||
| export const maxComputeSecondsTask = task({ | ||
| id: "max-duration-task", | ||
| maxDuration: timeout.None, // No max duration | ||
| maxComputeSeconds: timeout.None, // No max duration | ||
| run: async (payload: any, { ctx }) => { | ||
| //... | ||
| }, | ||
|
|
@@ -89,51 +93,51 @@ export const maxDurationTask = task({ | |
|
|
||
| ## Configuring for a run | ||
|
|
||
| You can set a `maxDuration` on a specific run when you trigger a task: | ||
| You can set a `maxComputeSeconds` on a specific run when you trigger a task: | ||
|
|
||
| ```ts /trigger/max-duration.ts | ||
| import { maxDurationTask } from "./trigger/max-duration-task"; | ||
| import { maxComputeSecondsTask } from "./trigger/max-duration-task"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Snippet import path is not runnable from the shown file location. In Proposed fix-import { maxComputeSecondsTask } from "./trigger/max-duration-task";
+import { maxComputeSecondsTask } from "./max-duration-task";
@@
-import { maxComputeSecondsTask } from "./trigger/max-duration-task";
+import { maxComputeSecondsTask } from "./max-duration-task";As per coding guidelines, Also applies to: 113-113 🤖 Prompt for AI Agents |
||
|
|
||
| // Trigger the task with a maxDuration of 300 seconds | ||
| const run = await maxDurationTask.trigger( | ||
| // Trigger the task with a maxComputeSeconds of 300 seconds | ||
| const run = await maxComputeSecondsTask.trigger( | ||
| { foo: "bar" }, | ||
| { | ||
| maxDuration: 300, // 300 seconds or 5 minutes | ||
| maxComputeSeconds: 300, // 300 seconds or 5 minutes | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| You can also set the `maxDuration` to `timeout.None` to turn off the max duration for a specific run: | ||
| You can also set the `maxComputeSeconds` to `timeout.None` to turn off the max duration for a specific run: | ||
|
|
||
| ```ts /trigger/max-duration.ts | ||
| import { maxDurationTask } from "./trigger/max-duration-task"; | ||
| import { maxComputeSecondsTask } from "./trigger/max-duration-task"; | ||
| import { timeout } from "@trigger.dev/sdk"; | ||
|
|
||
| // Trigger the task with no maxDuration | ||
| const run = await maxDurationTask.trigger( | ||
| // Trigger the task with no maxComputeSeconds | ||
| const run = await maxComputeSecondsTask.trigger( | ||
| { foo: "bar" }, | ||
| { | ||
| maxDuration: timeout.None, // No max duration | ||
| maxComputeSeconds: timeout.None, // No max duration | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## maxDuration in run context | ||
| ## maxComputeSeconds in run context | ||
|
|
||
| You can access the `maxDuration` set for a run in the run context: | ||
| You can access the `maxComputeSeconds` set for a run in the run context: | ||
|
|
||
| ```ts /trigger/max-duration-task.ts | ||
| import { task } from "@trigger.dev/sdk"; | ||
|
|
||
| export const maxDurationTask = task({ | ||
| export const maxComputeSecondsTask = task({ | ||
| id: "max-duration-task", | ||
| maxDuration: 300, // 300 seconds or 5 minutes | ||
| maxComputeSeconds: 300, // 300 seconds or 5 minutes | ||
| run: async (payload: any, { ctx }) => { | ||
| console.log(ctx.run.maxDuration); // 300 | ||
| console.log(ctx.run.maxComputeSeconds); // 300 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Documentation references At Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ## maxDuration and lifecycle functions | ||
| ## maxComputeSeconds and lifecycle functions | ||
|
|
||
| When a task run exceeds the `maxDuration`, the lifecycle functions `cleanup`, `onSuccess`, and `onFailure` will not be called. | ||
| When a task run exceeds the `maxComputeSeconds`, the lifecycle functions `cleanup`, `onSuccess`, and `onFailure` will not be called. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Documentation note says the opposite of what's intended — claims
maxDurationreplacesmaxComputeSecondsThe deprecation note in the documentation has the old and new names swapped, telling users the exact opposite of the PR's intent.
Details
At
docs/runs/max-duration.mdx:10, the note reads:But the entire PR is about deprecating
maxDurationin favor ofmaxComputeSeconds. The note should say:Impact: Users reading this documentation will be confused about which property to use — the note directly contradicts all other documentation and code changes in this PR.
Was this helpful? React with 👍 or 👎 to provide feedback.