Set a maximum duration for a task to run.
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.
You must set a default maxDuration in your trigger.config.ts
file, which will apply to all tasks unless overridden:
maxDuration
for a run in the following ways:
maxDuration
is set in seconds, and is compared to the CPU time elapsed since the start of a single execution (which we call 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
callstriggerAndWait
callsbatchTriggerAndWait
callsusage
utility:
maxDuration
you set. If the task exceeds the maxDuration
, it will be stopped with the following error:
maxDuration
on a specific task:
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.
You can “turn off” the Max duration set in your config file for a specific task like so:
maxDuration
on a specific run when you trigger a task:
maxDuration
to timeout.None
to turn off the max duration for a specific run:
maxDuration
set for a run in the run context:
maxDuration
, the lifecycle functions cleanup
, onSuccess
, and onFailure
will not be called.