Skip to content

Commit f3f7355

Browse files
committed
remove the docs from this PR
1 parent 0d3bc3c commit f3f7355

File tree

1 file changed

+0
-84
lines changed

1 file changed

+0
-84
lines changed

docs/triggering.mdx

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -831,90 +831,6 @@ export const myTask = task({
831831

832832
For more information, see our [Idempotency](/idempotency) documentation.
833833

834-
### `debounce`
835-
836-
You can debounce task triggers to consolidate multiple trigger calls into a single delayed run. When a run with the same debounce key already exists in the delayed state, subsequent triggers "push" the existing run's execution time later rather than creating new runs.
837-
838-
This is useful for scenarios like:
839-
840-
- Real-time document indexing where you want to wait for the user to finish typing
841-
- Aggregating webhook events from the same source
842-
- Rate limiting expensive operations while still processing the final request
843-
844-
```ts
845-
// First trigger creates a new run, delayed by 5 seconds
846-
await myTask.trigger({ some: "data" }, { debounce: { key: "user-123", delay: "5s" } });
847-
848-
// If triggered again within 5 seconds, the existing run is pushed later
849-
await myTask.trigger({ updated: "data" }, { debounce: { key: "user-123", delay: "5s" } });
850-
851-
// The run only executes after 5 seconds of no new triggers
852-
// Note: The first payload is used (first trigger wins)
853-
```
854-
855-
<Note>
856-
Debounce keys are scoped to the task identifier, so different tasks can use the same key without
857-
conflicts.
858-
</Note>
859-
860-
The `debounce` option accepts:
861-
862-
- `key` - A unique string to identify the debounce group (scoped to the task)
863-
- `delay` - Duration string specifying how long to delay (e.g., "5s", "1m", "30s")
864-
- `mode` - Optional. Controls which trigger's data is used: `"leading"` (default) or `"trailing"`
865-
866-
**How it works:**
867-
868-
1. First trigger with a debounce key creates a new delayed run
869-
2. Subsequent triggers with the same key (while the run is still delayed) push the execution time further
870-
3. Once no new triggers occur within the delay duration, the run executes
871-
4. After the run starts executing, a new trigger with the same key will create a new run
872-
873-
**Leading vs Trailing mode:**
874-
875-
By default, debounce uses **leading mode** - the run executes with data from the **first** trigger.
876-
877-
With **trailing mode**, each subsequent trigger updates the run's data (payload, metadata, tags, maxAttempts, maxDuration, and machine), so the run executes with data from the **last** trigger:
878-
879-
```ts
880-
// Leading mode (default): runs with first payload
881-
await myTask.trigger({ count: 1 }, { debounce: { key: "user-123", delay: "5s" } });
882-
await myTask.trigger({ count: 2 }, { debounce: { key: "user-123", delay: "5s" } });
883-
// After 5 seconds, runs with { count: 1 }
884-
885-
// Trailing mode: runs with last payload
886-
await myTask.trigger({ count: 1 }, { debounce: { key: "user-123", delay: "5s", mode: "trailing" } });
887-
await myTask.trigger({ count: 2 }, { debounce: { key: "user-123", delay: "5s", mode: "trailing" } });
888-
// After 5 seconds, runs with { count: 2 }
889-
```
890-
891-
Use **trailing mode** when you want to process the most recent data, such as:
892-
- Saving the latest version of a document after edits stop
893-
- Processing the final state after a series of rapid updates
894-
895-
**With `triggerAndWait`:**
896-
897-
When using `triggerAndWait` with debounce, the parent run blocks on the existing debounced run if one exists:
898-
899-
```ts
900-
export const parentTask = task({
901-
id: "parent-task",
902-
run: async (payload: string) => {
903-
// Both will wait for the same run
904-
const result = await childTask.triggerAndWait(
905-
{ data: payload },
906-
{ debounce: { key: "shared-key", delay: "3s" } }
907-
);
908-
return result;
909-
},
910-
});
911-
```
912-
913-
<Note>
914-
Idempotency keys take precedence over debounce keys. If both are provided and an idempotency match
915-
is found, it wins.
916-
</Note>
917-
918834
### `queue`
919835

920836
When you trigger a task you can override the concurrency limit. This is really useful if you sometimes have high priority runs.

0 commit comments

Comments
 (0)