This is a recipe that will make you wait for it...
There are two different kinds of wait tasks, tasks that wait for a duration and tasks that wait for a specific date and time until they proceed.
We need to create an action to help us track time. It will just log the current date and time. The action already exists in the action
folder com.packtpub.Orchestrator-Cookbook2ndEdition.helpers
:
getNow
. There is no need to define any in- or out-parameters.var current = new Date(); System.log(current);
sleepTime
in-parameter as input for the workflow.getNow
action we have just created before and after the Sleep task.waitDate
in-parameter as input for the workflow.getNow
action we have just created before and after the Wait until date task.
A wait task will pause the workflow execution for a certain amount of time. The main difference between a Sleep task and a Wait until task is the amount of system resources that are used for waiting.
The Sleep task will just wait; however, it will still require memory and one thread per sleep task. The Wait until task is more specific in how it saves system resources. When the Wait until task starts, the workflow is saved to the Orchestrator database and is woken up again on the specified date and time. Orchestrator uses a single thread to deal with the all the workflows that are set to wait until a certain date/time. This preserves quite a bit of resources.
This leads us directly to the most important usage for wait tasks, long-running workflows. If a workflow is running for a long time, such as polling for new e-mails or waiting for a user interaction, a wait task can reduce the amount of system resources consumed during the wait period.
There are actually two waits for date tasks, one in Generic called Waiting timer and the other in Basic called Wait until date. Both are essentially the same.
The JavaScript commands for waiting are System.sleep([milliseconds])
and System.waitUntil([Date],[Number of milliseconds])
.
Please note that the sleep
command works with milliseconds, whereas the Sleep schema element works with seconds.
The waituntil
command has two inputs: the date and the number of milliseconds. The milliseconds define the delay time between two checks to see whether a certain date has been reached. Also, the command returns a Boolean value that is true
when the wait has finished.