Skip to content

Commit a2cc7f9

Browse files
committed
added more details to the migrate AI prompt
1 parent 420f558 commit a2cc7f9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ await myTask.trigger({ foo: "bar" });
151151
await myTask.trigger({ foo: "bar" }, { queue: "my-queue" });
152152

153153

154-
**Lifecycle hooks**: Function signatures have changed to use a single object parameter instead of separate parameters. This is the old version:
154+
**Lifecycle hooks**: Function signatures have changed to use a single object parameter instead of separate parameters. Prefer `onStartAttempt` over the deprecated `onStart` when you need code to run before each attempt. This is the old version:
155155

156156

157157
// Old v3 way
@@ -171,10 +171,10 @@ This is the new version:
171171
// New v4 way - single object parameter for hooks
172172
export const myTask = task({
173173
id: "my-task",
174-
onStart: ({ payload, ctx }) => {},
175-
onSuccess: ({ payload, output, ctx }) => {},
176-
onFailure: ({ payload, error, ctx }) => {},
177-
catchError: ({ payload, ctx, error, retry }) => {},
174+
onStartAttempt: ({ payload, ctx }) => {}, // prefer over deprecated onStart
175+
onSuccess: ({ payload, ctx, task, output }) => {},
176+
onFailure: ({ payload, ctx, task, error }) => {},
177+
catchError: ({ payload, ctx, task, error, retry, retryAt, retryDelayInMs }) => {},
178178
run: async (payload, { ctx }) => {}, // run function unchanged
179179
});
180180

@@ -204,6 +204,12 @@ const batch = await batch.retrieve(batchHandle.batchId); // Use batch.retrieve()
204204
console.log(batch.runs);
205205

206206

207+
**triggerAndWait / batchTriggerAndWait**: In v4 these return a Result object, not the raw output. Use `if (result.ok) { ... result.output }` or call `.unwrap()` to get the output (throws if the run failed). Do not wrap `triggerAndWait` or `batchTriggerAndWait` in `Promise.all` — this is not supported.
208+
209+
210+
**Context (ctx) changes**: `ctx.attempt.id` and `ctx.attempt.status` have been removed; use `ctx.attempt.number` where needed. `ctx.task.exportName` has been removed.
211+
212+
207213
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.
208214

209215
```

0 commit comments

Comments
 (0)