Cancel on timeouts TypeScript & Go only

It's possible to force runs to cancel if they take too long to start, or if the runs execute for too long. The timeouts configuration property allows you to automatically cancel functions based off of two timeout properties:

  • timeouts.start, which controls how long a function can stay unstarted in the queue
  • timeouts.finish, which controls how long a function can execute once started

In the following examples, we'll explore how to configure the timeout property and how this works.

timeouts.start - Adding timeouts to unstarted runs

Runs may stay in the queue waiting to start due to concurrency backlogs, throttling configurations, or other delays. You can cancel functions automatically if they stay unstarted for too long.

The timeouts.start configuration property controls this timeout. This example forces runs to cancel if it takes over 10 seconds to successfully start the first step of a run:

inngest/function.ts

const scheduleReminder = inngest.createFunction(
  {
    id: "schedule-reminder",
    timeouts: {
      // If the run takes longer than 10s to start, cancel the run.
      start: "10s",
    },
  }
  { event: "tasks/reminder.created" },
  async ({ event, step }) => {
    await step.run('send-reminder-push', async () => {
      await pushNotificationService.push(event.data.reminder)
    })
  }
  // ...
);

timeouts.finish - Adding timeouts to executing runs

You may want to limit the overall duration of a run after the run starts executing. You can cancel functions automatically if they're executing for too long.

The timeouts.finish configuration property controls this timeout. This example forces runs to cancel if it takes over 30 seconds to finish, once started:

inngest/function.ts

const scheduleReminder = inngest.createFunction(
  {
    id: "schedule-reminder",
    timeouts: {
      // If the run takes longer than 10s to start, cancel the run.
      start: "10s",
      // And if the run takes longer than 30s to finish after starting, cancel the run.
      finish: "30s",
    },
  }
  { event: "tasks/reminder.created" },
  async ({ event, step }) => {
    await step.run('send-reminder-push', async () => {
      await pushNotificationService.push(event.data.reminder)
    })
  }
  // ...
);

Tips

  • The timeouts.start duration limits how long a run waits in the queue for the first step to start
  • Once the first attempt of a step begins, the timeouts.start property no longer applies. Instead, the timeouts.finish duration begins.
  • Once started, the timeouts.finish duration limits how long a run can execute
  • Both properties can be stacked to control the overall length of a function run