You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See our [maxDuration guide](/runs/max-duration) for more information.
352
352
353
+
## TTL
354
+
355
+
You can set a default time-to-live (TTL) for all task runs in your project. If a run is not dequeued within this time, it will expire and never execute.
356
+
357
+
```ts trigger.config.ts
358
+
import { defineConfig } from"@trigger.dev/sdk";
359
+
360
+
exportdefaultdefineConfig({
361
+
project: "<project ref>",
362
+
// Your other config settings...
363
+
ttl: "1h", // Also accepts a number of seconds, e.g. 3600
364
+
});
365
+
```
366
+
367
+
You can override this on a per-task basis by setting `ttl` on the task definition, or per-trigger by passing `ttl` in the trigger options. To opt a specific task out of the config-level TTL, set `ttl: 0` on the task. See [Time-to-live (TTL)](/runs#time-to-live-ttl) for more information.
368
+
353
369
## Process keep alive
354
370
355
371
Keep the process alive after the task has finished running so the next task doesn't have to wait for the process to start up again.
Copy file name to clipboardExpand all lines: docs/runs.mdx
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,12 +153,58 @@ When a run is canceled:
153
153
154
154
### Time-to-live (TTL)
155
155
156
-
TTL is a time-to-live setting that defines the maximum duration a run can remain in a queued state before being automatically expired. You can set a TTL when triggering a run:
156
+
TTL is a time-to-live setting that defines the maximum duration a run can remain in a queued state before being automatically expired. You can set a TTL at three levels, with the following precedence:
Similarly, to opt out of a config-level TTL for a specific task, set `ttl: 0` on the task definition:
193
+
194
+
```ts
195
+
exportconst longRunningTask =task({
196
+
id: "long-running-task",
197
+
ttl: 0, // Opt out of the config-level TTL
198
+
run: async (payload) => {
199
+
//...
200
+
},
201
+
});
202
+
```
203
+
204
+
<Note>
205
+
Setting `ttl: 0` removes the config-level or task-level TTL, but the platform-level maximum still applies. See [Limits - Maximum run TTL](/limits#maximum-run-ttl) for details.
206
+
</Note>
207
+
162
208
If the run hasn't started within the specified TTL, it will automatically expire, returning the status `Expired`. This is useful for time-sensitive tasks where immediate execution is important. For example, when you queue many runs simultaneously and exceed your concurrency limits, some runs might be delayed - using TTL ensures they only execute if they can start within your specified timeframe.
163
209
164
210
Dev runs automatically have a 10-minute TTL. On Trigger.dev Cloud, staging and production runs have a maximum TTL of 14 days applied automatically (runs without an explicit TTL get 14 days; longer TTLs are clamped). See [Limits — Maximum run TTL](/limits#maximum-run-ttl) for details.
See our [maxDuration guide](/runs/max-duration) for more information.
148
148
149
+
### `ttl` option
150
+
151
+
You can set a default time-to-live (TTL) on a task. If a run is not dequeued within this time, it will expire and never execute. This is useful for time-sensitive tasks where stale runs should be discarded.
152
+
153
+
```ts /trigger/time-sensitive-task.ts
154
+
exportconst timeSensitiveTask =task({
155
+
id: "time-sensitive-task",
156
+
ttl: "10m", // Also accepts a number of seconds, e.g. 600
157
+
run: async (payload:any, { ctx }) => {
158
+
//...
159
+
},
160
+
});
161
+
```
162
+
163
+
You can override this per-trigger by passing `ttl` in the trigger options, or set a project-wide default in your [trigger.config.ts](/config/config-file#ttl). Set `ttl: 0` to opt out of a config-level TTL. See [Time-to-live (TTL)](/runs#time-to-live-ttl) for more information.
164
+
149
165
## Global lifecycle hooks
150
166
151
167
<Note>When specifying global lifecycle hooks, we recommend using the `init.ts` file.</Note>
Copy file name to clipboardExpand all lines: docs/tasks/scheduled.mdx
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,18 @@ You can see from the comments that the payload has several useful properties:
67
67
68
68
Like all tasks they don't have timeouts, they should be placed inside a [/trigger folder](/config/config-file), and you [can configure them](/tasks/overview#defining-a-task).
69
69
70
+
You can set a [TTL](/runs#time-to-live-ttl) on a scheduled task to automatically expire runs that aren't dequeued in time. This is useful when a schedule fires while the previous run is still executing - rather than queueing up stale runs, they'll expire:
71
+
72
+
```ts
73
+
exportconst frequentTask =schedules.task({
74
+
id: "frequent-task",
75
+
ttl: "5m",
76
+
run: async (payload) => {
77
+
//...
78
+
},
79
+
});
80
+
```
81
+
70
82
## How to attach a schedule
71
83
72
84
Now that we've defined a scheduled task, we need to define when it will actually run. To do this we need to attach one or more schedules.
0 commit comments