Skip to content

Waiting tasks and custom events

Some workflows have to wait: for tonight’s change window, for a vCenter task to finish, for another system to say it’s done. Recipe 3.3 waited with System.sleep in a loop, which is fine for a few seconds or minutes. For anything longer, a sleeping run wastes a server thread and is lost if the server restarts. Orchestrator has better ways to wait.

In this recipe you build two small workflows. Pause until an hour uses a waiting timer to suspend a run until a set time of day. Wait for a signal holds a run until another workflow, Send a signal, sends it a custom event, or until a deadline passes.

Getting ready

  • The folder VCF Orchestrator Guide/Chapter 3.
  • The time zone of the Orchestrator server. The appliance usually runs in UTC, so a workflow that waits until 22:00 waits until 22:00 UTC, which is 03:30 the next morning in India.

On the lab’s embedded Orchestrator 9.1.1, new Date().toString() in a script returns a time such as Mon Nov 30 2026 17:03:30 GMT-0000 (GMT): scripts work in UTC, whatever the time zone of the person who runs the workflow.

How to do it

Work out when to wake up

  1. Create a workflow called Pause until an hour in VCF Orchestrator Guide/Chapter 3, with an input wakeHour of type number.
  2. On the Variables tab, add a variable wakeDate of type Date.
  3. On the Schema tab, add a scriptable task called Work out the wake-up time, with wakeHour in and wakeDate out:
Pause until an hour — Work out the wake-up time
// The next time the server's clock reads wakeHour:00, today or tomorrow
var now = new Date();
wakeDate = new Date(now.getTime());
wakeDate.setHours(wakeHour, 0, 0, 0);
if (wakeDate.getTime() <= now.getTime()) {
wakeDate.setDate(wakeDate.getDate() + 1);
}
System.log("Waiting until " + wakeDate);

Add the waiting timer

  1. Drag a Waiting timer from the Generic group onto the arrow after Work out the wake-up time.
  2. Select it. Under Inputs, bind its parameter timer.date to wakeDate.
  3. After the timer, add a scriptable task called Carry on, with this one line:
Pause until an hour — Carry on
System.log("Woke up at " + new Date());
Schema tab of Pause until an hour: Start, Work out the wake-up time, Waiting timer, Carry on, End. The waiting timer is selected (item3: Waiting timer): Details with Name, Next element item2: Carry on and Business status; Inputs: timer.date (Date) bound to wakeDate; Exception handling.
Figure 3.23. A waiting timer, with its date bound to a variable.
  1. Save and run it, with wakeHour set to the next hour on the server’s clock. The run logs the time it’ll wait until, then shows as Waiting Signal in Activity > Workflow Runs. At the top of the hour it carries on, logs the second line, and completes.
The run of Pause until an hour in the Waiting Signal state. The canvas highlights the Waiting timer element between Work out the wake-up time and Carry on; the log shows Waiting until Fri Nov 20 2026 19:00:00 GMT.
Figure 3.24. A run suspended by a waiting timer, in the Waiting Signal state.

The schema element reference shows the same waiting timer in figure R.10.

Wait for a custom event

  1. Create a workflow called Wait for a signal, with an input eventName of type string, an input waitMinutes of type number, and an output signalled of type boolean.
  2. Add a variable endDate of type Date, and a variable isExternalEvent of type boolean with the value false.
  3. Add a scriptable task called Set the deadline, with eventName and waitMinutes in and endDate out:
Wait for a signal — Set the deadline
endDate = new Date(new Date().getTime() + waitMinutes * 60 * 1000);
System.log("Waiting for '" + eventName + "' until " + endDate);
  1. Open the Basic group of the palette. Drag the predefined task Wait for custom event onto the arrow after Set the deadline.
  2. Select it and open Inputs/Outputs. Bind its inputs: isExternalEvent to isExternalEvent, eventName to eventName, and endDate to endDate. Bind its output success to signalled.
Schema tab of Wait for a signal: Start, Set the deadline, Wait for custom event (an hourglass with a red flag), End. Wait for custom event is selected (item2: Scriptable task). Inputs/Outputs: inputs isExternalEvent (boolean), eventName (string) and endDate (Date) bound to the variables of the same name; output success (boolean) bound to signalled.
Figure 3.25. The predefined Wait for custom event task, with its inputs bound.

Like every Basic task, its script is generated and read-only; the Scripting tab shows it.

Send the event from another workflow

  1. Create a workflow called Send a signal, with one input eventName of type string.
  2. Drag the predefined task Send custom event, also in the Basic group, onto its schema and bind its input eventName to the workflow input. Save.
  3. Run Wait for a signal with eventName = vcfguide-signal-test and waitMinutes = 30. It shows as Running, not Waiting: this task waits inside its script (see How it works).
  4. Run Send a signal with the same eventName. Within a few seconds, the waiting run completes, and its signalled output is true. In the lab it completed two seconds after the send.
  5. Run Wait for a signal again with waitMinutes = 2, and send nothing. After two minutes, the run completes with signalled = false.
Activity, Workflow Runs, filtered on signal: Send a signal completed at 10:40:07 PM; a Wait for a signal run started at 10:39:31 PM still Running; the Wait for a signal run started at 10:39:30 PM completed at 10:40:10 PM, two seconds after the send.
Figure 3.26. A custom event releases the waiting run; the run from step 17 is still waiting, shown as Running.

How it works

Every running workflow has a thread on the Orchestrator server. A scriptable task that calls System.sleep(60000) keeps its thread for the whole minute, doing nothing. A few of those are harmless. A few hundred, each waiting an hour, use up the threads that other runs need.

The waiting timer and the waiting event element are Orchestrator’s long-running elements. When a run reaches one, Orchestrator saves the run’s state to its database and frees the thread. One background thread then watches all the suspended runs on the server. For a waiting timer, it checks the date in timer.date. For a waiting event, it checks a trigger, an object that fires when something happens elsewhere. When the date passes or the trigger fires, the run is picked up again, with all its slots as they were, and carries on with the next element. Because the state is in the database, a suspended run survives a restart of the server.

Custom events are named signals inside Orchestrator. The predefined task Send custom event calls System.sendCustomEvent(eventName), which sends an event with that name to every workflow and policy waiting for it. Wait for custom event calls System.waitCustomEventUntil, which waits until an event with that name arrives or endDate passes. It returns the event, or null on timeout, and the task turns that into success. The name is the only link between sender and receiver, so make it unique, for example by putting a request number in it.

You can call the same methods from your own scripts:

Sending and waiting for a custom event in a script
// requestId is a string input of both workflows
// In the sending workflow
System.sendCustomEvent("vcfguide-signal-" + requestId);
// In the waiting workflow: "internal" means an HTTP request can't send this event
var deadline = new Date(new Date().getTime() + 30 * 60 * 1000);
var event = System.waitCustomEventUntil("internal", "vcfguide-signal-" + requestId, deadline);
if (event === null) {
throw "No signal for request " + requestId + " within 30 minutes";
}

Wait for custom event holds its thread. Tested on 9.1.1: a run inside Wait for custom event shows as Running, not Waiting Signal, because System.waitCustomEventUntil waits inside the script. That’s fine for minutes. For waits of hours, or hundreds of runs at once, prefer a long-running element: a waiting timer, a waiting event or a user interaction.

Needs a lab check. Check whether an event sent on one node of a three-node cluster reaches a run waiting on another node (needs the standalone cluster).
Back in vRO 5.5–7Drag a Waiting Timer or Waiting Event from the Java client's Generic menu, then click the Not set link on its IN tab to bind timer.date or trigger.ref.
In Orchestrator 9.xDrag a Waiting timer or Waiting event from the Generic group in the browser, and bind the same parameter on its Inputs tab. The custom event tasks and methods haven't changed.

There's more

Wait for a vCenter task without a loop. The Waiting event element takes a trigger.ref input of type Trigger. The vSphere plug-in can make one from any vCenter task: trigger = task.createEndOfTaskTrigger(timeoutSeconds); in a scriptable task directly before the waiting event. The run sleeps in the database until the task ends or the timeout passes. Every trigger needs a timeout. The lab workflow Snapshot a VM and wait does exactly this and is shown in the schema element reference: the run shows Waiting Signal until the snapshot task ends. The usual alternative, the library action vim3WaitTaskEnd, polls in a loop and holds a thread the whole time.

Plan for a wake-up that comes late. If the server is down when a waiting timer’s date passes, the run can fail with “Timeout on signal” when the server starts again, instead of carrying on. Give the timer an exception path (recipe 3.4) if missing the time matters.

Needs a lab check. Reproduce the late wake-up in the lab: run Pause until an hour, stop the Orchestrator service past the wake time, start it again, and note whether the run fails with “Timeout on signal” or carries on.

Other ready-made waits. The Basic group also has the predefined tasks Sleep and Wait until date. Both hold the thread: their generated scripts call System.sleep and System.waitUntil. Use them for seconds or minutes, and a waiting timer for anything longer.

Wait for a person. A User interaction element is a waiting event whose trigger is a person answering a form. Recipe 3.9 builds an approval with it.

Time out every wait. A run that waits for ever is a run nobody remembers. Give every custom event a deadline, every trigger a timeout, and test what happens when the time runs out, as step 17 does.

Don’t wait at all. If nothing needs to happen until a set time, schedule the workflow instead of starting it and making it wait. Recipe 3.8 shows the Schedule workflow element, and Chapter 7 covers scheduling and policies.

See also