Skip to content

Commit acc10e8

Browse files
0skiericallam
andauthored
chore(docs): add more cost saving tips (#2806)
Co-authored-by: Eric Allam <eallam@icloud.com>
1 parent f1a83cf commit acc10e8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/how-to-reduce-your-spend.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,45 @@ export const boundedTask = task({
168168
},
169169
});
170170
```
171+
172+
## Use waitpoints instead of polling
173+
174+
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.
175+
176+
```ts
177+
import { task, wait } from "@trigger.dev/sdk";
178+
179+
export const waitpointTask = task({
180+
id: "waitpoint-task",
181+
run: async (payload) => {
182+
// This wait is free - your task is checkpointed
183+
await wait.for({ minutes: 5 });
184+
185+
// Parent is also checkpointed while waiting for child tasks
186+
const result = await childTask.triggerAndWait({ data: payload });
187+
return result;
188+
},
189+
});
190+
```
191+
192+
[Read more about waitpoints](/wait-for).
193+
194+
## Use debounce to consolidate multiple triggers
195+
196+
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.
197+
198+
```ts
199+
// Multiple rapid triggers consolidate into 1 run
200+
await updateIndex.trigger(
201+
{ docId: "doc-123" },
202+
{ debounce: { key: "doc-123", delay: "5s" } }
203+
);
204+
205+
// Use trailing mode to process the most recent payload
206+
await processUpdate.trigger(
207+
{ version: 2 },
208+
{ debounce: { key: "update-123", delay: "10s", mode: "trailing" } }
209+
);
210+
```
211+
212+
[Read more about debounce](/triggering#debounce).

0 commit comments

Comments
 (0)