Skip to content

Commit 909be39

Browse files
committed
add docs
1 parent cd116a5 commit 909be39

2 files changed

Lines changed: 166 additions & 0 deletions

File tree

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
"management/runs/retrieve",
334334
"management/runs/replay",
335335
"management/runs/cancel",
336+
"management/runs/bulk-actions",
336337
"management/runs/reschedule",
337338
"management/runs/update-metadata",
338339
"management/runs/add-tags",
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: "Bulk actions"
3+
description: "Cancel or replay many runs from the SDK using run IDs or the same filters as runs.list()."
4+
---
5+
6+
**Bulk actions let you cancel or replay many runs asynchronously from the SDK by selecting runs with run IDs or `runs.list()` filters.**
7+
8+
A bulk action returns a handle immediately. Use the handle to retrieve progress, poll until completion, list previous actions, or abort pending work.
9+
10+
## Create a bulk replay
11+
12+
Use `runs.bulk.replay()` to replay every run that matches a filter.
13+
14+
```ts Your backend code
15+
import { runs } from "@trigger.dev/sdk";
16+
17+
const action = await runs.bulk.replay({
18+
filter: {
19+
status: "FAILED",
20+
taskIdentifier: "sync-customer",
21+
period: "24h",
22+
},
23+
name: "Replay failed customer syncs",
24+
targetRegion: "eu-central-1",
25+
});
26+
27+
const completed = await runs.bulk.poll(action.id);
28+
console.log(completed.status, completed.counts);
29+
```
30+
31+
`filter` accepts the same filters as [`runs.list()`](/management/runs/list), excluding pagination fields. Relative time filters such as `period` are resolved when the bulk action is created, so later batches process the same fixed time range.
32+
33+
<ParamField body="filter" type="BulkActionFilter">
34+
Selects runs using the same filter shape as `runs.list()`, excluding `limit`, `after`, and `before`.
35+
</ParamField>
36+
37+
<ParamField body="runIds" type="string[]">
38+
Selects specific run IDs. Provide either `filter` or `runIds`, not both.
39+
</ParamField>
40+
41+
<ParamField body="name" type="string" optional>
42+
A name for the bulk action.
43+
</ParamField>
44+
45+
<ParamField body="targetRegion" type="string" optional>
46+
Replays matching runs in a specific region. When omitted, each replay keeps the original run's region. This option is only available for `runs.bulk.replay()`.
47+
</ParamField>
48+
49+
## Create a bulk cancel
50+
51+
Use `runs.bulk.cancel()` to cancel every run that matches a filter, or specific run IDs.
52+
53+
```ts Your backend code
54+
import { runs } from "@trigger.dev/sdk";
55+
56+
const action = await runs.bulk.cancel({
57+
runIds: ["run_1234", "run_5678"],
58+
name: "Cancel selected runs",
59+
});
60+
61+
console.log(action.id);
62+
```
63+
64+
Only runs that are still cancelable when the action reaches them are canceled. Runs that have already reached a final state count as failures in the bulk action summary.
65+
66+
## Retrieve progress
67+
68+
Use `runs.bulk.retrieve()` to read the current status and aggregate counts.
69+
70+
```ts Your backend code
71+
import { runs } from "@trigger.dev/sdk";
72+
73+
const action = await runs.bulk.retrieve("bulk_1234");
74+
75+
console.log(action.status);
76+
console.log(action.counts.total, action.counts.success, action.counts.failure);
77+
```
78+
79+
The returned bulk action object has these fields:
80+
81+
<ResponseField name="id" type="string">
82+
The bulk action ID, starting with `bulk_`.
83+
</ResponseField>
84+
85+
<ResponseField name="type" type="'CANCEL' | 'REPLAY'">
86+
The action being performed.
87+
</ResponseField>
88+
89+
<ResponseField name="status" type="'PENDING' | 'COMPLETED' | 'ABORTED'">
90+
The current bulk action status.
91+
</ResponseField>
92+
93+
<ResponseField name="counts" type="object">
94+
Aggregate processing counts.
95+
96+
<Expandable title="properties">
97+
<ResponseField name="total" type="number">
98+
The number of runs selected when the bulk action was created.
99+
</ResponseField>
100+
<ResponseField name="success" type="number">
101+
The number of runs processed successfully.
102+
</ResponseField>
103+
<ResponseField name="failure" type="number">
104+
The number of runs that could not be processed.
105+
</ResponseField>
106+
</Expandable>
107+
</ResponseField>
108+
109+
<ResponseField name="createdAt" type="Date">
110+
The date and time the bulk action was created.
111+
</ResponseField>
112+
113+
<ResponseField name="completedAt" type="Date" optional>
114+
The date and time the bulk action completed.
115+
</ResponseField>
116+
117+
## Poll for completion
118+
119+
Use `runs.bulk.poll()` to wait until the bulk action leaves the `PENDING` state.
120+
121+
```ts Your backend code
122+
import { runs } from "@trigger.dev/sdk";
123+
124+
const completed = await runs.bulk.poll("bulk_1234", {
125+
pollIntervalMs: 2_000,
126+
});
127+
128+
console.log(completed.status);
129+
```
130+
131+
## Abort a bulk action
132+
133+
Use `runs.bulk.abort()` to stop future batches from being processed.
134+
135+
```ts Your backend code
136+
import { runs } from "@trigger.dev/sdk";
137+
138+
await runs.bulk.abort("bulk_1234");
139+
```
140+
141+
Abort is best effort. Runs already being processed in the current batch may still finish.
142+
143+
## List bulk actions
144+
145+
Use `runs.bulk.list()` to page through previous bulk actions in the current environment.
146+
147+
```ts Your backend code
148+
import { runs } from "@trigger.dev/sdk";
149+
150+
const page = await runs.bulk.list({ limit: 25 });
151+
152+
for (const action of page.data) {
153+
console.log(action.id, action.status);
154+
}
155+
```
156+
157+
List results support the same auto-pagination helpers as other management API list methods:
158+
159+
```ts Your backend code
160+
import { runs } from "@trigger.dev/sdk";
161+
162+
for await (const action of runs.bulk.list({ limit: 25 })) {
163+
console.log(action.id, action.status);
164+
}
165+
```

0 commit comments

Comments
 (0)