Sleep until step.sleepUntil()

Use step.sleepUntil() to pause the execution of your function until a specific date time.

Please note that at maximum, functions can sleep for a year (seven days for the free tier plans).

export default inngest.createFunction(
  { id: "send-scheduled-reminder" },
  { event: "app/reminder.scheduled" },
  async ({ event, step }) => {
    const date = new Date(event.data.remind_at);
    await step.sleepUntil("wait-for-scheduled-reminder", date);
    // Do something else
  }
);

To sleep until a particular amount of time from now, use step.sleep() instead.


step.sleepUntil(id, datetime): Promise

  • Name
    id
    Type
    string
    Required
    required
    Description

    The ID of the step. This will be what appears in your function's logs and is used to memoize step state across function versions.

  • Name
    datetime
    Type
    Date | string
    Required
    required
    Description

    The datetime at which to continue execution of your function. This can be:

// Sleep until the new year
await step.sleepUntil("happy-new-year", "2024-01-01");

// Sleep until September ends
await step.sleepUntil("wake-me-up", "2023-09-30T11:59:59");

// Sleep until the end of the this week
const date = dayjs().endOf("week").toDate();
await step.sleepUntil("wait-for-end-of-the-week", date);

step.sleepUntil() must be called using await or some other Promise handler to ensure your function sleeps correctly.