Skip to main content
A run can stop for a set time, then resume: a reminder three days after sign-up, a follow-up a week after an order, a new attempt an hour after a failure. While it sleeps, your app has nothing running and nothing in memory. Nelkap keeps the run, and calls your app again when the time is up. To pause until something happens rather than for a set time, see Wait for an event.

Sleep for a duration

Call step.sleep with a duration:
nelkap/workflows/send-trial-reminder.ts
Started when a trial begins, this run sleeps for 11 days, then sends the reminder. The sleep ends the call: the code after it runs in a later call, once the 11 days are over.

Durations

A duration is a whole number and a unit, like 30 seconds or 3 days. The unit can be singular or plural. A month from January 31 runs past the end of February and ends in early March. A sleep lasts up to a year.

Wake-up time

Nelkap checks sleeping runs every minute, so a run resumes within a minute after its time is up. A sleep of a few seconds therefore lasts up to a minute. When the run wakes, Nelkap calls your app, and your workflow runs from its first line: the steps before the sleep return their saved results, the sleep returns at once, and the work after it runs.
For a pause shorter than a minute, like a second between two requests to a rate-limited API, wait inside the step that makes the requests. The step holds the call open meanwhile, so keep such pauses short.

Sleep until a date

step.sleep takes a duration. To sleep until a date, work out the duration in a step, so every call of the run gets the same one:
This run sends its reminder a day before the event. The number of hours is saved, so a later call doesn’t compute a new one from a later time. If the event is less than a day away, the duration is 0 hours, and the sleep returns at once, without pausing the run.

Sleep names

A sleep is saved like a step, named after its duration. When a run reaches two sleeps of 1 day, the first matches the first saved one, and the second matches the second.
Changing a sleep’s duration in your code changes its name. A run that already slept reaches it on its next call as a new sleep, and pauses a second time. See Versioning.

Errors

Like any error your workflow doesn’t catch, either one fails the run. Every code is described in Errors.

Cancel a sleeping run

While a run sleeps, you can cancel it from its page, for example when the user upgrades before the trial reminder goes out. See Cancel a run.