Skip to content

Commit 0707e65

Browse files
committed
Improved migrating docs
1 parent 4e6b72f commit 0707e65

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

docs/migrating-from-v3.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,14 @@ const batchHandle = await tasks.batchTrigger([
292292
const runs = await batchHandle.runs.list();
293293
console.log(runs);
294294
```
295+
296+
### OpenTelemetry
297+
298+
We are now using newer versions of the OpenTelemetry packages. This means that if you're using custom exporters you may need to update the packages:
299+
300+
| Package | Previous Version | New Version | Change Type |
301+
| ----------------------------------------- | ---------------- | ----------- | ------------ |
302+
| `@opentelemetry/api-logs` | 0.52.1 | 0.203.0 | Major update |
303+
| `@opentelemetry/exporter-logs-otlp-http` | 0.52.1 | 0.203.0 | Major update |
304+
| `@opentelemetry/exporter-trace-otlp-http` | 0.52.1 | 0.203.0 | Major update |
305+
| `@opentelemetry/instrumentation` | 0.52.1 | 0.203.0 | Major update |

docs/snippets/migrate-v4-using-ai.mdx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<Accordion title="Copy paste this prompt in full" icon="sparkles">
22

3+
```md
4+
35
I would like you to help me migrate my v3 task code to v4. Here are the important differences:
46

57
We've deprecated the `@trigger.dev/sdk/v3` import path and moved to a new path:
68

7-
```ts
89
// This is the old path
910
import { task } from "@trigger.dev/sdk/v3";
1011

1112
// This is the new path, use this instead
1213
import { task } from "@trigger.dev/sdk";
13-
```
1414

1515
We've renamed the `handleError` hook to `catchError`. Use this instead of `handleError`.
1616

1717
`init` was previously used to initialize data used in the run function. This is the old version:
1818

19-
```ts
2019
import { task } from "@trigger.dev/sdk";
2120

2221
const myTask = task({
@@ -30,11 +29,9 @@ const myTask = task({
3029
await client.doSomething();
3130
},
3231
});
33-
```
3432

3533
This is the new version using middleware and locals:
3634

37-
```ts
3835
import { task, locals, tasks } from "@trigger.dev/sdk";
3936

4037
// Create a local for your client
@@ -58,11 +55,9 @@ const myTask = task({
5855
await client.doSomething();
5956
},
6057
});
61-
```
6258

6359
We’ve deprecated the `toolTask` function and replaced it with the `ai.tool` function, which creates an AI tool from an existing `schemaTask`. This is the old version:
6460

65-
```ts
6661
import { toolTask, schemaTask } from "@trigger.dev/sdk";
6762
import { z } from "zod";
6863
import { generateText } from "ai";
@@ -87,11 +82,9 @@ export const myAiTask = schemaTask({
8782
});
8883
},
8984
});
90-
```
9185

9286
This is the new version:
9387

94-
```ts
9588
import { schemaTask, ai } from "@trigger.dev/sdk";
9689
import { z } from "zod";
9790
import { generateText } from "ai";
@@ -124,20 +117,19 @@ export const myAiTask = schemaTask({
124117
});
125118
},
126119
});
127-
```
128120

129121
We've made several breaking changes that require code updates:
130122

131123
**Queue changes**: Queues must now be defined ahead of time using the `queue` function. You can no longer create queues "on-demand" when triggering tasks. This is the old version:
132124

133-
```ts
125+
134126
// Old v3 way - creating queue on-demand
135127
await myTask.trigger({ foo: "bar" }, { queue: { name: "my-queue", concurrencyLimit: 10 } });
136-
```
128+
137129

138130
This is the new version:
139131

140-
```ts
132+
141133
// New v4 way - define queue first
142134
import { queue, task } from "@trigger.dev/sdk";
143135

@@ -157,11 +149,11 @@ await myTask.trigger({ foo: "bar" });
157149

158150
// Or specify queue by name
159151
await myTask.trigger({ foo: "bar" }, { queue: "my-queue" });
160-
```
152+
161153

162154
**Lifecycle hooks**: Function signatures have changed to use a single object parameter instead of separate parameters. This is the old version:
163155

164-
```ts
156+
165157
// Old v3 way
166158
export const myTask = task({
167159
id: "my-task",
@@ -171,11 +163,11 @@ export const myTask = task({
171163
catchError: (payload, { ctx, error, retry }) => {},
172164
run: async (payload, { ctx }) => {},
173165
});
174-
```
166+
175167

176168
This is the new version:
177169

178-
```ts
170+
179171
// New v4 way - single object parameter for hooks
180172
export const myTask = task({
181173
id: "my-task",
@@ -185,23 +177,23 @@ export const myTask = task({
185177
catchError: ({ payload, ctx, error, retry }) => {},
186178
run: async (payload, { ctx }) => {}, // run function unchanged
187179
});
188-
```
180+
189181

190182
**BatchTrigger changes**: The `batchTrigger` function no longer returns runs directly. This is the old version:
191183

192-
```ts
184+
193185
// Old v3 way
194186
const batchHandle = await tasks.batchTrigger([
195187
[myTask, { foo: "bar" }],
196188
[myOtherTask, { baz: "qux" }],
197189
]);
198190

199191
console.log(batchHandle.runs); // Direct access
200-
```
192+
201193

202194
This is the new version:
203195

204-
```ts
196+
205197
// New v4 way
206198
const batchHandle = await tasks.batchTrigger([
207199
[myTask, { foo: "bar" }],
@@ -210,8 +202,11 @@ const batchHandle = await tasks.batchTrigger([
210202

211203
const runs = await batchHandle.runs.list(); // Use runs.list()
212204
console.log(runs);
213-
```
205+
214206

215207
Can you help me convert the following code from v3 to v4? Please include the full converted code in the answer, do not truncate it anywhere.
216208

217-
</Accordion>
209+
```
210+
211+
</Accordion>
212+

docs/snippets/node-versions.mdx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
Trigger.dev runs your tasks on specific Node.js versions:
22

3-
- **v3**: Uses Node.js `21.7.3`
4-
- **v4**: Uses Node.js `21.7.3`
3+
### v3
4+
5+
- Node.js `21.7.3`
6+
7+
### v4
8+
9+
- Node.js `21.7.3` (default)
10+
- Node.js `22.16.0` (`node-22`)
11+
- Bun `1.2.20` (`bun`)
12+
13+
You can change the runtime by setting the `runtime` field in your `trigger.config.ts` file.
14+
15+
```ts
16+
import { defineConfig } from "@trigger.dev/sdk/v3";
17+
18+
export default defineConfig({
19+
// "node", "node-22" or "bun"
20+
runtime: "node-22",
21+
project: "<your-project-ref>",
22+
});
23+
```

0 commit comments

Comments
 (0)