Waiting tasks

This is a recipe that will make you wait for it...

Getting ready

We need a new workflow and time!

How to do 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.

Creating a help task

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:

  1. Create a new action and call it getNow. There is no need to define any in- or out-parameters.
  2. In the script section, place the following script:
          var current = new Date(); 
          System.log(current); 
    

Using the Sleep task

  1. Create a new workflow.
  2. Drag a Sleep task onto the schema and create the sleepTime in-parameter as input for the workflow.
  3. Add the getNow action we have just created before and after the Sleep task.
  4. When running the workflow, check the log. You will notice how the workflow will wait for the allocated seconds.

Waiting for a date

  1. Create a new workflow.
  2. Drag a Wait until date task onto the schema and create the waitDate in-parameter as input for the workflow.
  3. Add the getNow action we have just created before and after the Wait until date task.
  4. When running the workflow, check out the log. You will notice how the workflow will wait until the allocated date and time:

    Waiting for a date

How it works...

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.

There's more...

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.

Tip

No JavaScript wait tasks will save any system resources, as the schema tasks do.

See also

See the example workflows:

  • 06.04.01 Sleep
  • 06.04.02 Wait until date
  • 06.04.03 Working with date attributes

See the example actions: getNow and setNow.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset