Minor Changes
-
Realtime streams v2 (#2632)
-
Prevent uncaught errors in the
onSuccess,onComplete, andonFailurelifecycle hooks from failing attempts/runs. (#2515)Deprecated the
onStartlifecycle hook (which only fires before therunfunction on the first attempt). Replaced withonStartAttemptthat fires before the run function on every attempt:export const taskWithOnStartAttempt = task({ id: "task-with-on-start-attempt", onStartAttempt: async ({ payload, ctx }) => { //... }, run: async (payload: any, { ctx }) => { //... }, }); // Default a global lifecycle hook using tasks tasks.onStartAttempt(({ ctx, payload, task }) => { console.log( `Run ${ctx.run.id} started on task ${task} attempt ${ctx.run.attempt.number}`, ctx.run ); });
If you want to execute code before just the first attempt, you can use the
onStartAttemptfunction and checkctx.run.attempt.number === 1:export const taskWithOnStartAttempt = task({ id: "task-with-on-start-attempt", onStartAttempt: async ({ payload, ctx }) => { if (ctx.run.attempt.number === 1) { console.log("Run started on attempt 1", ctx.run); } }, });
Patch Changes
- Updated dependencies:
@trigger.dev/core@4.1.0