Delay function
Learn more about the delay workflow function within Knock's notification engine.
A delay function does just what it sounds like: it delays the execution of the workflow for some amount of time, then proceeds to the next step. There are four types of delays we support in Knock today: "wait for fixed interval", "wait for a dynamic period", "wait until a relative timestamp", and "wait until a time window."
By default, that continuation uses the latest published version of the workflow.
Wait for a fixed interval
#The "wait for fixed interval" delay type waits for an interval of time (provided by you in the workflow editor) and then proceeds to the next step.
Fixed interval delay functions are helpful for the following use cases:
- Check to see if a user's seen or read an in-app message before sending an email
- Remind a user about a pending invite they haven't accepted
A fixed interval can be at most 365 days.
Wait for a dynamic period
#You can also set the length of your delay dynamically using a variable. You can use any of the data, recipient, actor, or environment variables associated with the workflow run to set your duration.
When specifying a dynamic delay period you must provide one of the following:
- An ISO-8601 timestamp (e.g.
2027-05-04T20:34:07Z) which must be a datetime in the future - A duration unit (e.g
{ "unit": "seconds", "value": 30 }) - A window rule (e.g
{ "frequency": "daily", "hours": 9, "minutes": 30 })
A dynamic delay must be available to be resolved via the key you specify on the given schema, meaning that if you specify a key of delayUntil in your data schema, your workflow trigger data must contain either an ISO-8601 timestamp, a valid duration unit, or a valid window rule under that key.
When the specified key is missing or resolves to an invalid value, a corresponding error will be logged on the workflow run, and the delay will be skipped. If the resolved time is more than 365 days after the delay step runs, Knock logs an error and halts the entire workflow run. See how long a workflow can be delayed for alternatives.
Wait until a relative timestamp
#You can use our relative delay to wait some time before or after a timestamp that you provide in your workflow payload. This computes a delay time for a fixed interval relative to a dynamic timestamp.
Relative delay functions are helpful for various scenarios, including:
- Appointment reminders: send a notification one day before an appointment time
- Follow-up reminders: send a follow-up message two hours after an event
When configuring a relative delay, you'll specify:
- A fixed delay interval (provided by you in the workflow editor)
- Whether the delay should occur before or after the dynamic timestamp
- The
keyfor the dynamic timestamp (which can come from your trigger data, recipient data, or other sources)
As in the dynamic delay section above, the specified key must be available to be resolved. If the key is missing or resolves to an invalid value, a corresponding error will be logged on the workflow run, and the delay will be skipped. If the computed time is more than 365 days after the delay step runs, Knock logs an error and halts the workflow run. For example, a delay set to end one day before a timestamp 400 days out resolves to 399 days and halts the run.
Wait until a time window
#A time window delay holds the workflow until the recipient is inside a weekly schedule you define, such as business hours, and then continues to the next step. Use it when the rest of the workflow should only run at a reasonable time for the recipient.
For example, say the schedule is open Monday through Friday from 9am to 6pm. A workflow run that reaches the delay on a Saturday waits until Monday at 9am, then continues. A run that reaches the delay at 2pm on a Tuesday is already inside the schedule, so it continues without waiting.
To set one up, choose Window as the delay type on the delay step, then mark each day of the week as open or closed. A day can stay open all day or between a start and end time, set in 15 minute increments. At least one day must be open.
Knock evaluates the delay window in the recipient's timezone when one is set, and falls back to the account default timezone, then Etc/UTC. A recipient in New York and a recipient in London each wait for 9am in their own timezone.
A few things to keep in mind:
- Editing the schedule doesn't move waiting runs. A run that is already paused on the step keeps the time it was given. Cancel the workflow run if you need to stop it.
- Time window delays are different from send windows. A time window delay pauses the whole workflow. A channel step send window only holds that channel's message while the workflow run proceeds. If a later channel step has its own send windows and they're closed when a delay ends, that step's message will wait until its send window opens.
- The Window option is not a window rule. A window rule is a dynamic delay value, such as "delay until Monday at 9am", that you pass in your trigger data.
Setting the workflow version mode
#A delay step can continue on the latest workflow version or stay pinned to the version that started the delay. New delay steps default to latest mode.
Set this on the delay step with the "Continue on latest version" toggle. You can also set workflow_version_mode to latest or pinned when you manage the workflow through the Management API or CLI.
Latest (default)
#In latest mode, when the delay elapses, Knock continues the workflow on the newest published version that still includes this delay step with latest mode enabled. That version is either the one that started the run, or a version published after it. Template and step changes on that version are used for the continuation.
Use latest mode for long delays, such as onboarding or reminders, so template and step edits published during the delay apply when the run resumes.
Pinned
#Pinned mode ties the delay to the workflow version that started the run. When the delay elapses, the run continues on that version, using the templates and steps from that version.
Pinned is an advanced option. Use it when a delayed run should stay on the version that started it.
Using workflow cancellation with delays
#In cases where you're waiting to see if a user will complete an action before sending a notification, you can use our workflow cancellation API to ensure a user doesn't receive an unnecessary reminder.
If the user completes the action you were going to remind them about, cancel the workflow to keep any additional notifications from being sent.