Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/how-it-works.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Here's how the Checkpoint-Resume System works:

2. **Subtask Handling**: If a task needs to trigger a subtask, it can do so and wait for its completion using `triggerAndWait`

3. **State Checkpointing**: While waiting for a subtask or during a programmed pause (e.g., `wait.for({ seconds: 30 })`), the system uses CRIU (Checkpoint/Restore In Userspace) to create a checkpoint of the task's entire state, including memory, CPU registers, and open file descriptors.
3. **State Checkpointing**: While waiting for a subtask or during a long programmed pause (e.g., `wait.for({ minutes: 5 })`), the system uses CRIU (Checkpoint/Restore In Userspace) to create a checkpoint of the task's entire state, including memory, CPU registers, and open file descriptors. A `wait.for()` or `wait.until()` shorter than 60 seconds doesn't checkpoint — see [Wait](/wait).

4. **Resource Release**: After checkpointing, the parent task's resources are released, freeing up the execution environment.

Expand Down Expand Up @@ -178,9 +178,9 @@ export const parentTask = task({
console.log("Child task result:", result);

// This will also cause the task to be checkpointed and suspended
await wait.for({ seconds: 30 });
await wait.for({ minutes: 5 });

console.log("Resumed after 30 seconds");
console.log("Resumed after 5 minutes");

return "Parent task completed";
},
Expand Down
8 changes: 4 additions & 4 deletions docs/how-to-reduce-your-spend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ export const boundedTask = task({

## Use waitpoints instead of polling

Waits longer than 5 seconds automatically checkpoint your task, meaning you don't pay for compute while waiting. Use `wait.for()`, `wait.until()`, or `triggerAndWait()` instead of polling loops.
You don't pay for compute during any wait longer than 5 seconds. Use `wait.for()`, `wait.until()`, or `triggerAndWait()` instead of polling loops.

```ts
Comment thread
matt-aitken marked this conversation as resolved.
import { task, wait } from "@trigger.dev/sdk";

export const waitpointTask = task({
id: "waitpoint-task",
run: async (payload) => {
// This wait is free - your task is checkpointed
// You aren't charged for compute during this wait
await wait.for({ minutes: 5 });

// Parent is also checkpointed while waiting for child tasks
// The parent isn't charged either while it waits for a child task
const result = await childTask.triggerAndWait({ data: payload });
return result;
},
});
```

[Read more about waitpoints](/wait-for).
Waiting saves you compute, but it doesn't always free up concurrency — see [Wait](/wait).

## Use debounce to consolidate multiple triggers

Expand Down
4 changes: 4 additions & 0 deletions docs/queue-concurrency.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ For example, if you have a queue with a `concurrencyLimit` of 1:
- When the executing run reaches a waitpoint and checkpoints, it releases its slot
- The next queued run can then begin execution

### Short time-based waits keep their slot

Checkpointing takes time, so a run doesn't checkpoint the moment it reaches a waitpoint. For [`wait.for()`](/wait-for) and [`wait.until()`](/wait-until) it happens 60 seconds into the wait, so anything shorter stays `EXECUTING` and holds its slot for the whole wait. If you're polling in a loop, use an interval comfortably above 60 seconds so the slot is actually released between polls.

### Waiting for a subtask on a different queue

When a parent task triggers and waits for a subtask on a different queue, the parent task will checkpoint and release its concurrency slot once it reaches the wait point. This prevents environment deadlocks where all concurrency slots would be occupied by waiting tasks.
Expand Down
4 changes: 3 additions & 1 deletion docs/snippets/paused-execution-free.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for
longer than a few seconds.

When triggering and waiting for subtasks, the parent is checkpointed and while waiting does not count towards compute usage. When waiting for a time period (`wait.for` or `wait.until`), if the wait is longer than 5 seconds we checkpoint and it does not count towards compute usage.
When triggering and waiting for subtasks, the parent is checkpointed and while waiting does not count towards compute usage. When waiting for a time period (`wait.for` or `wait.until`), a wait longer than 5 seconds does not count towards compute usage.

Free compute isn't the same as freed concurrency: the concurrency slot is only released once we've snapshotted the machine and shut it down. For `wait.for` and `wait.until` that happens 60 seconds into the wait, so anything shorter stays `EXECUTING` and holds its slot for the whole wait.