Skip to content

Commit 80cb649

Browse files
author
deepshekhardas
committed
feat(sdk): replace maxDuration with maxComputeSeconds (user-facing rename)
1 parent debfa2b commit 80cb649

17 files changed

Lines changed: 158 additions & 34 deletions

.changeset/max-compute-seconds.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@trigger.dev/core": patch
3+
"@trigger.dev/sdk": patch
4+
"trigger.dev": patch
5+
---
6+
7+
Add `maxComputeSeconds` as the user-facing replacement for `maxDuration` on `defineConfig`, task definitions, and trigger options. The new name makes the unit (compute-time seconds) unambiguous at the call site. `maxDuration` is JSDoc-deprecated and still accepted; if both are set, `maxComputeSeconds` wins. The `init` templates have been updated to use the new name.

packages/cli-v3/src/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,16 @@ function validateConfig(config: TriggerConfig, warn = true) {
359359
config.build.extensions.push(adaptResolveEnvVarsToSyncEnvVarsExtension(resolveEnvVarsFn));
360360
}
361361

362-
if (!config.maxDuration) {
362+
// Resolve maxComputeSeconds → maxDuration so plain-object exports that bypass
363+
// defineConfig() still work. This mirrors the resolution defineConfig() applies
364+
// at the SDK boundary; downstream CLI/runtime code only reads `maxDuration`.
365+
const resolvedMaxDuration = config.maxComputeSeconds ?? config.maxDuration;
366+
if (!resolvedMaxDuration) {
363367
throw new Error(
364-
`The "maxDuration" trigger.config option is now required, and must be at least 5 seconds.`
368+
`The "maxComputeSeconds" trigger.config option is now required, and must be at least 5 seconds.`
365369
);
366370
}
371+
config.maxDuration = resolvedMaxDuration;
367372

368373
if (config.runtime && config.runtime === "bun") {
369374
warn &&

packages/cli-v3/templates/examples/schedule.mjs.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export const firstScheduledTask = schedules.task({
44
id: "first-scheduled-task",
55
// Every hour
66
cron: "0 * * * *",
7-
// Set an optional maxDuration to prevent tasks from running indefinitely
8-
maxDuration: 300, // Stop executing after 300 secs (5 mins) of compute
7+
// Set an optional maxComputeSeconds to prevent tasks from running indefinitely
8+
maxComputeSeconds: 300, // Stop executing after 300 secs (5 mins) of compute
99
run: async (payload, { ctx }) => {
1010
// The payload contains the last run timestamp that you can use to check if this is the first run
1111
// And calculate the time since the last run

packages/cli-v3/templates/examples/schedule.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export const firstScheduledTask = schedules.task({
44
id: "first-scheduled-task",
55
// Every hour
66
cron: "0 * * * *",
7-
// Set an optional maxDuration to prevent tasks from running indefinitely
8-
maxDuration: 300, // Stop executing after 300 secs (5 mins) of compute
7+
// Set an optional maxComputeSeconds to prevent tasks from running indefinitely
8+
maxComputeSeconds: 300, // Stop executing after 300 secs (5 mins) of compute
99
run: async (payload, { ctx }) => {
1010
// The payload contains the last run timestamp that you can use to check if this is the first run
1111
// And calculate the time since the last run

packages/cli-v3/templates/examples/simple.mjs.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { logger, task, wait } from "@trigger.dev/sdk/v3";
22

33
export const helloWorldTask = task({
44
id: "hello-world",
5-
// Set an optional maxDuration to prevent tasks from running indefinitely
6-
maxDuration: 300, // Stop executing after 300 secs (5 mins) of compute
5+
// Set an optional maxComputeSeconds to prevent tasks from running indefinitely
6+
maxComputeSeconds: 300, // Stop executing after 300 secs (5 mins) of compute
77
run: async (payload, { ctx }) => {
88
logger.log("Hello, world!", { payload, ctx });
99

packages/cli-v3/templates/examples/simple.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { logger, task, wait } from "@trigger.dev/sdk/v3";
22

33
export const helloWorldTask = task({
44
id: "hello-world",
5-
// Set an optional maxDuration to prevent tasks from running indefinitely
6-
maxDuration: 300, // Stop executing after 300 secs (5 mins) of compute
5+
// Set an optional maxComputeSeconds to prevent tasks from running indefinitely
6+
maxComputeSeconds: 300, // Stop executing after 300 secs (5 mins) of compute
77
run: async (payload: any, { ctx }) => {
88
logger.log("Hello, world!", { payload, ctx });
99

packages/cli-v3/templates/trigger.config.mjs.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export default defineConfig({
44
project: "${projectRef}",
55
runtime: "${runtime}",
66
logLevel: "log",
7-
// The max compute seconds a task is allowed to run. If the task run exceeds this duration, it will be stopped.
7+
// The max compute seconds a task is allowed to run. If the run exceeds this, it will be stopped.
88
// You can override this on an individual task.
99
// See https://trigger.dev/docs/runs/max-duration
10-
maxDuration: 3600,
10+
maxComputeSeconds: 3600,
1111
retries: {
1212
enabledInDev: true,
1313
default: {

packages/cli-v3/templates/trigger.config.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export default defineConfig({
44
project: "${projectRef}",
55
runtime: "${runtime}",
66
logLevel: "log",
7-
// The max compute seconds a task is allowed to run. If the task run exceeds this duration, it will be stopped.
7+
// The max compute seconds a task is allowed to run. If the run exceeds this, it will be stopped.
88
// You can override this on an individual task.
99
// See https://trigger.dev/docs/runs/max-duration
10-
maxDuration: 3600,
10+
maxComputeSeconds: 3600,
1111
retries: {
1212
enabledInDev: true,
1313
default: {

packages/core/src/v3/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,28 @@ export type TriggerConfig = {
165165
*/
166166
logLevel?: LogLevel;
167167

168+
/**
169+
* The maximum duration in compute-time **seconds** that a task run is allowed to run. If the task run exceeds this duration, it will be stopped.
170+
*
171+
* Minimum value is 5 seconds.
172+
*
173+
* Setting this value will affect all tasks in the project. You can override it on a per-task basis.
174+
*
175+
* @see https://trigger.dev/docs/tasks/overview#maxcomputeseconds-option
176+
*/
177+
maxComputeSeconds?: number;
178+
168179
/**
169180
* The maximum duration in compute-time seconds that a task run is allowed to run. If the task run exceeds this duration, it will be stopped.
170181
*
171182
* Minimum value is 5 seconds
172183
*
173184
* Setting this value will effect all tasks in the project.
174185
*
186+
* @deprecated Use `maxComputeSeconds` instead — same semantics, clearer unit. If both are set, `maxComputeSeconds` wins.
175187
* @see https://trigger.dev/docs/tasks/overview#maxduration-option
176188
*/
177-
maxDuration: number;
189+
maxDuration?: number;
178190

179191
/**
180192
* Set a default time-to-live (TTL) for all task runs in the project. If a run is not executed within this time, it will be removed from the queue and never execute.

packages/core/src/v3/errors.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ export class MaxDurationExceededError extends Error {
683683
public readonly maxDurationInSeconds: number,
684684
public readonly elapsedTimeInSeconds: number
685685
) {
686-
super(`Run exceeded maximum compute time (maxDuration) of ${maxDurationInSeconds} seconds`);
686+
super(
687+
`Run exceeded maximum compute time (maxComputeSeconds) of ${maxDurationInSeconds} seconds`
688+
);
687689

688690
this.name = "MaxDurationExceededError";
689691
}
@@ -715,6 +717,12 @@ const prettyInternalErrors: Partial<
715717
href: links.docs.machines.home,
716718
},
717719
},
720+
MAX_DURATION_EXCEEDED: {
721+
link: {
722+
name: "How to set maxComputeSeconds (maxDuration)",
723+
href: links.docs.maxDuration,
724+
},
725+
},
718726
TASK_PROCESS_MAYBE_OOM_KILLED: {
719727
message:
720728
"Your run was terminated due to exceeding the machine's memory limit. Try increasing the machine preset in your task options or replay using a larger machine.",

0 commit comments

Comments
 (0)