Skip to content

@trigger.dev/sdk@4.1.0

Latest

Choose a tag to compare

@github-actions github-actions released this 14 Nov 09:59
19fa669

Minor Changes

  • Realtime streams v2 (#2632)

  • Prevent uncaught errors in the onSuccess, onComplete, and onFailure lifecycle hooks from failing attempts/runs. (#2515)

    Deprecated the onStart lifecycle hook (which only fires before the run function on the first attempt). Replaced with onStartAttempt that 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 onStartAttempt function and check ctx.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