Sleep step.sleep()
Use step.sleep()
to pause the execution of your function for a specific amount of time. At maximum, functions can sleep for a year (seven days for the free tier plans).
Functions that are sleeping do not count towards concurrency limits.
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
}
);
To sleep until a particular date time, use step.sleepUntil()
instead.
step.sleep(id, duration): 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
duration
- Type
- number | string
- Required
- required
- Description
The duration of time to sleep:
- Number of milliseconds
- Time string compatible with the ms package, e.g.
"30m"
,"3 hours"
, or"2.5d"
// Sleep for 30 minutes
await step.sleep("wait-with-string", "30m");
await step.sleep("wait-with-string-alt", "30 minutes");
await step.sleep("wait-with-ms", 30 * 60 * 1000);
step.sleep()
must be called using await
or some other Promise handler to ensure your function sleeps correctly.