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
- Create a workflow called
Pause until an hourin VCF Orchestrator Guide/Chapter 3, with an inputwakeHourof typenumber. - On the Variables tab, add a variable
wakeDateof typeDate. - On the Schema tab, add a scriptable task called
Work out the wake-up time, withwakeHourin andwakeDateout:
// The next time the server's clock reads wakeHour:00, today or tomorrowvar 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
- Drag a Waiting timer from the Generic group onto the arrow after
Work out the wake-up time. - Select it. Under Inputs, bind its parameter
timer.datetowakeDate. - After the timer, add a scriptable task called
Carry on, with this one line:
System.log("Woke up at " + new Date());
- Save and run it, with
wakeHourset 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 schema element reference shows the same waiting timer in figure R.10.
Wait for a custom event
- Create a workflow called
Wait for a signal, with an inputeventNameof typestring, an inputwaitMinutesof typenumber, and an outputsignalledof typeboolean. - Add a variable
endDateof typeDate, and a variableisExternalEventof typebooleanwith the valuefalse. - Add a scriptable task called
Set the deadline, witheventNameandwaitMinutesin andendDateout:
endDate = new Date(new Date().getTime() + waitMinutes * 60 * 1000);System.log("Waiting for '" + eventName + "' until " + endDate);- Open the Basic group of the palette. Drag the predefined task Wait for custom event onto the arrow after
Set the deadline. - Select it and open Inputs/Outputs. Bind its inputs:
isExternalEventtoisExternalEvent,eventNametoeventName, andendDatetoendDate. Bind its outputsuccesstosignalled.

Like every Basic task, its script is generated and read-only; the Scripting tab shows it.
Send the event from another workflow
- Create a workflow called
Send a signal, with one inputeventNameof typestring. - Drag the predefined task Send custom event, also in the Basic group, onto its schema and bind its input
eventNameto the workflow input. Save. - Run
Wait for a signalwitheventName=vcfguide-signal-testandwaitMinutes=30. It shows as Running, not Waiting: this task waits inside its script (see How it works). - Run
Send a signalwith the sameeventName. Within a few seconds, the waiting run completes, and itssignalledoutput istrue. In the lab it completed two seconds after the send. - Run
Wait for a signalagain withwaitMinutes=2, and send nothing. After two minutes, the run completes withsignalled=false.

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:
// requestId is a string input of both workflows
// In the sending workflowSystem.sendCustomEvent("vcfguide-signal-" + requestId);
// In the waiting workflow: "internal" means an HTTP request can't send this eventvar 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.
timer.date or trigger.ref.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.
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
- 3.3 Decisions, switches, and loops, for the short
System.sleeploop this recipe replaces. - 3.8 Asynchronous and nested workflows, to start a workflow and carry on.
- Broadcom TechDocs (VCF 9): Developing Long-Running Workflows and Schema Elements and Schema Element Properties.
- Broadcom TechDocs (Aria Automation Orchestrator): Timer-based workflows and Trigger-based workflows.
- VMware type definitions for the Orchestrator scripting API (
System.sendCustomEvent,System.waitCustomEventUntil): build-tools-for-vmware-aria, o11n-core. - CloudBlogger, the author’s blog: Trigger-based long-running workflows in Orchestrator.
