chore(docs): add more cost saving tips (#2806)

Co-authored-by: Eric Allam <eallam@icloud.com>
This commit is contained in:
Oskar Otwinowski
2025-12-22 16:36:54 +01:00
committed by GitHub
parent f1a83cffc4
commit acc10e847c
+42
View File
@@ -168,3 +168,45 @@ 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.
```ts
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
await wait.for({ minutes: 5 });
// Parent is also checkpointed while waiting for child tasks
const result = await childTask.triggerAndWait({ data: payload });
return result;
},
});
```
[Read more about waitpoints](/wait-for).
## Use debounce to consolidate multiple triggers
When a task might be triggered multiple times in quick succession, use debounce to consolidate them into a single run. This is useful for document indexing, webhook aggregation, cache invalidation, and real-time sync scenarios.
```ts
// Multiple rapid triggers consolidate into 1 run
await updateIndex.trigger(
{ docId: "doc-123" },
{ debounce: { key: "doc-123", delay: "5s" } }
);
// Use trailing mode to process the most recent payload
await processUpdate.trigger(
{ version: 2 },
{ debounce: { key: "update-123", delay: "10s", mode: "trailing" } }
);
```
[Read more about debounce](/triggering#debounce).