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:


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

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


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

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


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

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