Skip to content

Commit 36c16f9

Browse files
committed
Add 4.3.0 rules with batch trigger v2 and debouncing features
1 parent dd51a19 commit 36c16f9

File tree

6 files changed

+957
-4
lines changed

6 files changed

+957
-4
lines changed

.claude/skills/trigger-dev-tasks/SKILL.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,54 @@ await myTask.trigger(payload, {
120120
machine: "large-1x", // micro, small-1x, small-2x, medium-1x, medium-2x, large-1x, large-2x
121121
maxAttempts: 3,
122122
tags: ["user_123"], // Max 10 tags
123+
debounce: { // Consolidate rapid triggers
124+
key: "unique-key",
125+
delay: "5s",
126+
mode: "trailing", // "leading" (default) or "trailing"
127+
},
123128
});
124129
```
125130

131+
## Debouncing
132+
133+
Consolidate multiple triggers into a single execution:
134+
135+
```ts
136+
// Rapid triggers with same key = single execution
137+
await myTask.trigger({ userId: "123" }, {
138+
debounce: {
139+
key: "user-123-update",
140+
delay: "5s",
141+
},
142+
});
143+
144+
// Trailing mode: use payload from LAST trigger
145+
await myTask.trigger({ data: "latest" }, {
146+
debounce: {
147+
key: "my-key",
148+
delay: "10s",
149+
mode: "trailing",
150+
},
151+
});
152+
```
153+
154+
Use cases: user activity updates, webhook deduplication, search indexing, notification batching.
155+
156+
## Batch Triggering
157+
158+
Up to 1,000 items per batch, 3MB per payload:
159+
160+
```ts
161+
const results = await myTask.batchTriggerAndWait([
162+
{ payload: { userId: "1" } },
163+
{ payload: { userId: "2" } },
164+
]);
165+
166+
for (const result of results) {
167+
if (result.ok) console.log(result.output);
168+
}
169+
```
170+
126171
## Machine Presets
127172

128173
| Preset | vCPU | Memory |

.claude/skills/trigger-dev-tasks/advanced-tasks.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Trigger.dev Advanced Tasks
1+
# Trigger.dev Advanced Tasks (v4)
22

33
**Advanced patterns and features for writing tasks**
44

@@ -36,6 +36,145 @@ for await (const run of runs.subscribeToRunsWithTag("user_123")) {
3636
- Max 10 tags per run, 1-64 characters each
3737
- Tags don't propagate to child tasks automatically
3838

39+
## Batch Triggering v2
40+
41+
Enhanced batch triggering with larger payloads and streaming ingestion.
42+
43+
### Limits
44+
45+
- **Maximum batch size**: 1,000 items (increased from 500)
46+
- **Payload per item**: 3MB each (increased from 1MB combined)
47+
- Payloads > 512KB automatically offload to object storage
48+
49+
### Rate Limiting (per environment)
50+
51+
| Tier | Bucket Size | Refill Rate |
52+
|------|-------------|-------------|
53+
| Free | 1,200 runs | 100 runs/10 sec |
54+
| Hobby | 5,000 runs | 500 runs/5 sec |
55+
| Pro | 5,000 runs | 500 runs/5 sec |
56+
57+
### Concurrent Batch Processing
58+
59+
| Tier | Concurrent Batches |
60+
|------|-------------------|
61+
| Free | 1 |
62+
| Hobby | 10 |
63+
| Pro | 10 |
64+
65+
### Usage
66+
67+
```ts
68+
import { myTask } from "./trigger/myTask";
69+
70+
// Basic batch trigger (up to 1,000 items)
71+
const runs = await myTask.batchTrigger([
72+
{ payload: { userId: "user-1" } },
73+
{ payload: { userId: "user-2" } },
74+
{ payload: { userId: "user-3" } },
75+
]);
76+
77+
// Batch trigger with wait
78+
const results = await myTask.batchTriggerAndWait([
79+
{ payload: { userId: "user-1" } },
80+
{ payload: { userId: "user-2" } },
81+
]);
82+
83+
for (const result of results) {
84+
if (result.ok) {
85+
console.log("Result:", result.output);
86+
}
87+
}
88+
89+
// With per-item options
90+
const batchHandle = await myTask.batchTrigger([
91+
{
92+
payload: { userId: "123" },
93+
options: {
94+
idempotencyKey: "user-123-batch",
95+
tags: ["priority"],
96+
},
97+
},
98+
{
99+
payload: { userId: "456" },
100+
options: {
101+
idempotencyKey: "user-456-batch",
102+
},
103+
},
104+
]);
105+
```
106+
107+
## Debouncing
108+
109+
Consolidate multiple triggers into a single execution by debouncing task runs with a unique key and delay window.
110+
111+
### Use Cases
112+
113+
- **User activity updates**: Batch rapid user actions into a single run
114+
- **Webhook deduplication**: Handle webhook bursts without redundant processing
115+
- **Search indexing**: Combine document updates instead of processing individually
116+
- **Notification batching**: Group notifications to prevent user spam
117+
118+
### Basic Usage
119+
120+
```ts
121+
await myTask.trigger(
122+
{ userId: "123" },
123+
{
124+
debounce: {
125+
key: "user-123-update", // Unique identifier for debounce group
126+
delay: "5s", // Wait duration ("5s", "1m", or milliseconds)
127+
},
128+
}
129+
);
130+
```
131+
132+
### Execution Modes
133+
134+
**Leading Mode** (default): Uses payload/options from the first trigger; subsequent triggers only reschedule execution time.
135+
136+
```ts
137+
// First trigger sets the payload
138+
await myTask.trigger({ action: "first" }, {
139+
debounce: { key: "my-key", delay: "10s" }
140+
});
141+
142+
// Second trigger only reschedules - payload remains "first"
143+
await myTask.trigger({ action: "second" }, {
144+
debounce: { key: "my-key", delay: "10s" }
145+
});
146+
// Task executes with { action: "first" }
147+
```
148+
149+
**Trailing Mode**: Uses payload/options from the most recent trigger.
150+
151+
```ts
152+
await myTask.trigger(
153+
{ data: "latest-value" },
154+
{
155+
debounce: {
156+
key: "trailing-example",
157+
delay: "10s",
158+
mode: "trailing",
159+
},
160+
}
161+
);
162+
```
163+
164+
In trailing mode, these options update with each trigger:
165+
- `payload` — task input data
166+
- `metadata` — run metadata
167+
- `tags` — run tags (replaces existing)
168+
- `maxAttempts` — retry attempts
169+
- `maxDuration` — maximum compute time
170+
- `machine` — machine preset
171+
172+
### Important Notes
173+
174+
- Idempotency keys take precedence over debounce settings
175+
- Compatible with `triggerAndWait()` — parent runs block correctly on debounced execution
176+
- Debounce key is scoped to the task
177+
39178
## Concurrency & Queues
40179

41180
```ts
@@ -339,6 +478,8 @@ export const publicWorkflow = task({
339478
- **Metadata**: Track progress for long-running tasks
340479
- **Machines**: Match machine size to computational requirements
341480
- **Tags**: Use consistent naming patterns for filtering
481+
- **Debouncing**: Use for user activity, webhooks, and notification batching
482+
- **Batch triggering**: Use for bulk operations up to 1,000 items
342483
- **Error Handling**: Distinguish between retryable and fatal errors
343484

344485
Design tasks to be stateless, idempotent, and resilient to failures. Use metadata for state tracking and queues for resource management.

.claude/skills/trigger-dev-tasks/basic-tasks.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Trigger.dev Basic Tasks
1+
# Trigger.dev Basic Tasks (v4)
22

33
**MUST use `@trigger.dev/sdk`, NEVER `client.defineJob`**
44

@@ -58,13 +58,46 @@ const handle = await tasks.trigger<typeof processData>("process-data", {
5858
data: [{ id: 1 }, { id: 2 }],
5959
});
6060

61-
// Batch trigger
61+
// Batch trigger (up to 1,000 items, 3MB per payload)
6262
const batchHandle = await tasks.batchTrigger<typeof processData>("process-data", [
6363
{ payload: { userId: "123", data: [{ id: 1 }] } },
6464
{ payload: { userId: "456", data: [{ id: 2 }] } },
6565
]);
6666
```
6767

68+
### Debounced Triggering
69+
70+
Consolidate multiple triggers into a single execution:
71+
72+
```ts
73+
// Multiple rapid triggers with same key = single execution
74+
await myTask.trigger(
75+
{ userId: "123" },
76+
{
77+
debounce: {
78+
key: "user-123-update", // Unique key for debounce group
79+
delay: "5s", // Wait before executing
80+
},
81+
}
82+
);
83+
84+
// Trailing mode: use payload from LAST trigger
85+
await myTask.trigger(
86+
{ data: "latest-value" },
87+
{
88+
debounce: {
89+
key: "trailing-example",
90+
delay: "10s",
91+
mode: "trailing", // Default is "leading" (first payload)
92+
},
93+
}
94+
);
95+
```
96+
97+
**Debounce modes:**
98+
- `leading` (default): Uses payload from first trigger, subsequent triggers only reschedule
99+
- `trailing`: Uses payload from most recent trigger
100+
68101
### From Inside Tasks (with Result handling)
69102

70103
```ts
@@ -149,6 +182,7 @@ export const taskWithWaits = task({
149182
- **Result vs Output**: `triggerAndWait()` returns a `Result` object with `ok`, `output`, `error` properties - NOT the direct task output
150183
- **Type safety**: Use `import type` for task references when triggering from backend
151184
- **Waits > 5 seconds**: Automatically checkpointed, don't count toward compute usage
185+
- **Debounce + idempotency**: Idempotency keys take precedence over debounce settings
152186

153187
## NEVER Use (v2 deprecated)
154188

0 commit comments

Comments
 (0)