Changelog #82

·

Max duration

Set a maximum duration for a task to run, and automatically cancel it if it exceeds this limit.

Eric Allam

Eric Allam

CTO, Trigger.dev

Image for Max duration

Trigger.dev, the background jobs platform with no timeouts, is proud to announce the release of timeouts (but only when you want them).

You can now set a maxDuration for a task, for when you want to prevent runaway tasks:


_10
import { task } from "@trigger.dev/sdk/v3";
_10
_10
export const maxDurationTask = task({
_10
id: "max-duration-task",
_10
maxDuration: 300, // 300 seconds or 5 minutes
_10
run: async (payload: { foo: string }) => {
_10
//...
_10
},
_10
});

Or you can set a global maxDuration for all tasks in your project:


_10
import { defineConfig } from "@trigger.dev/sdk/v3";
_10
_10
export default defineConfig({
_10
maxDuration: 300, // 300 seconds or 5 minutes
_10
});

You can even set a specific maxDuration for a run when you trigger a task:


_10
import { maxDurationTask } from "./trigger/max-duration-task";
_10
_10
// Trigger the task with a maxDuration of 300 seconds
_10
// This will override the default maxDuration set in the config file
_10
const run = await maxDurationTask.trigger(
_10
{ foo: "bar" },
_10
{
_10
maxDuration: 300, // 300 seconds or 5 minutes
_10
}
_10
);

Read all about the maxDuration feature in the docs.

Update

Max duration is available starting from @trigger.dev/sdk version 3.0.10, upgrade using npx trigger.dev@latest update. If you are self-hosting, upgrade to version 3.0.10 or later of the server image.

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now
,