Failure handlers

If your function exhausts all of its retries, it will be marked as "Failed." You can handle this circumstance by providing an onFailure handler when defining your function.

The example below checks if a user's subscription is valid a total of six times. If you can't check the subscription after all retries, you'll unsubscribe the user:

inngest.createFunction(
  {
    id: "update-subscription",
    retries: 5,
    onFailure: async ({ event, error }) => {
      // if the subscription check fails after all retries, unsubscribe the user
      await unsubscribeUser(event.data.userId);
    },
  },
  { event: "user/subscription.check" },
  async ({ event }) => { /* ... */ },
);

Internally, this handler creates a second function that listens for the inngest/function.failed event, which you can listen to yourself to capture all failed runs across your system.

inngest.createFunction(
  { id: "handle-any-fn-failure" },
  { event: "inngest/function.failed" },
  async ({ event }) => { /* ... */ },
);