Sleeps
Two step methods are available to pause the execution of your function for a specific amount of time.
Using sleep methods can save the need for running multiple cron jobs and additional queues. For example, Step Pauses enables you to create a user onboarding workflow that sequences multiple actions in time: first send a welcome email, then send a tutorial everyday during the first week.
How sleeps works
Each step method informs Inngest to resume execution at a future time. Your code does not need to be running during this enabling sleeps to be used in any environment, even serverless.
This implies that Function being paused by a sleeping Step won't affect your account capacity (ex, your Function's concurrency capacity).
Pausing an execution for a given time
Use step.sleep()
to pause the execution of your function for a specific amount of time.
export default inngest.createFunction(
{ id: "send-delayed-email" },
{ event: "app/user.signup" },
async ({ event, step }) => {
await step.sleep("wait-a-couple-of-days", "2d");
// Do something else
}
);
Check out the step.sleep()
TypeScript reference.
Pausing an execution until a given date
Use step.sleepUntil()
to pause the execution of your function until a specific date time.
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
}
);
Check out the step.sleepUntil()
TypeScript reference.
About: Maximum sleep duration
Functions can sleep for a year (seven days for the free tier plans).