Orchestrator Trigger Workflows: Wait for vCenter Tasks Without Busy Threads
Trigger based waits suspend Orchestrator runs while vCenter works. Set a timeout, check task status, and handle unfinished tasks in the error path.

Long vCenter operations can keep an Orchestrator workflow active while it polls for completion. That’s manageable for a task lasting seconds; clones, migrations and large snapshots can take much longer, and concurrent polling runs add up. A trigger based workflow lets the run suspend while vCenter works, then resume when the task ends. The key operational detail is that a timeout ends the wait, but doesn’t automatically stop the vCenter task.

The workflow described here was tested with VCF Operations Orchestrator 9.1.1 (build 25643527), embedded in VCF Automation 9.1, and the vCenter plug-in. The design follows the TechDocs guidance for trigger based workflows.
A trigger resumes an existing run
Most ways of sending work to Orchestrator create a new workflow run: examples include the REST API, schedules, the UI, Workflow.execute() from a script, the VCF Automation event broker, and plug-in or policy based events. A trigger works differently. It wakes a run that has already reached a Waiting event and suspended.

SNMP and AMQP can be used in either pattern. A policy can start a fresh run for each incoming trap or message. A trigger can instead resume the particular run waiting for that event. For a vCenter operation, the trigger watches the task returned by the operation, so the workflow can step aside and continue in the same run when that task ends.
Build the wait around a VC:Task
The pattern has two parts. First, a scriptable task creates a Trigger from the VC:Task returned by a vCenter operation, using task.createEndOfTaskTrigger(timeout). Immediately after it, a Waiting event receives the trigger through its trigger.ref input. Once the workflow reaches that event, Orchestrator places the run in Waiting Signal. The run has no thread of its own while it waits; the product documentation describes a server thread watching the state of long running workflows.
When the vCenter task ends, the workflow resumes at the next element. The trigger indicates that the task ended, but doesn’t say whether it succeeded. The workflow must inspect the task state itself.
Example: create a snapshot, wait, then clean up
The demonstration creates a VM snapshot with memory included, waits for the snapshot task through a trigger, checks the result and removes the snapshot. Inputs are vm (VC:VirtualMachine), snapshotName (string), includeMemory (boolean) and timeoutSec (number). The workflow also keeps task (VC:Task), trigger (Trigger), startedAtMs (number) and errorCode (string).

The operation must return a VC:Task. The example uses the vCenter plug-in’s createSnapshot_Task method and records the start time for logging:
if (!vm) { throw "vm is required"; }
if (!timeoutSec || timeoutSec <= 0) {
throw "timeoutSec must be greater than 0";
}
var name = snapshotName ? snapshotName : "trigger-demo";
task = vm.createSnapshot_Task(
name,
"Temporary snapshot for the trigger-based wait demo",
includeMemory === true,
false
);
startedAtMs = new Date().getTime();Next, create the trigger in a scriptable task with task and timeoutSec as inputs and a Trigger as its output. This element must sit directly before the Waiting event. A timeout is essential: without one, the run can remain waiting indefinitely if the task never reports back.
trigger = task.createEndOfTaskTrigger(timeoutSec);
System.log("Trigger created; suspending until the vCenter task ends.");
Add a Waiting event from the Generic elements and bind its trigger.ref input to the workflow’s trigger variable.

Configure exception handling on the Waiting event. Bind its error to a string variable such as errorCode, then connect the error path to a separate scriptable task. This gives the workflow a place to respond when the wait times out.
Check task state after the trigger fires
The trigger fires when the task ends, whether the result is success or error. After the Waiting event, inspect task.info.state.value, log the elapsed time and fail the run if the state is not success. For an error state, the task’s localized message can provide detail:
var info = task.info;
var taskState = info.state.value;
var waitedSec = Math.round(
(new Date().getTime() - startedAtMs) / 1000
);
System.log("Resumed after " + waitedSec + " s. Task state: " + taskState);
if (taskState == "error") {
var reason = info.error
? info.error.localizedMessage
: "no error details";
throw "Snapshot task failed: " + reason;
}
if (taskState != "success") {
throw "Snapshot task ended in unexpected state: " + taskState;
}The demo removes the snapshot after a successful check. That cleanup step deliberately uses vim3WaitTaskEnd to show the older polling approach alongside the trigger based wait:
var snapshot = task.info.result;
var removeTask = snapshot.removeSnapshot_Task(false, true);
System.getModule("com.vmware.library.vc.basic")
.vim3WaitTaskEnd(removeTask, false, 2);
System.log("Snapshot removed");What the run and timeout showed
With includeMemory set to true and a 300 second timeout, the run reached Waiting Signal a few milliseconds after it started. The snapshot took 64 seconds. Orchestrator then resumed the workflow, logged a success state and removed the snapshot. The recorded sequence was: snapshot creation at 23:27:01.154, trigger creation at 23:27:01.181, resumption at 23:28:05.306, and snapshot removal at 23:28:09.360. Those are the times from the test run, not a general estimate for snapshot duration.


A five second timeout exposed three behaviours to account for. First, the Waiting event raises Timeout on signal and follows its configured exception path. Without that path, the workflow fails at the Waiting event. Second, the timeout wasn’t exact in these tests: runs with a five second setting failed after 9.5 seconds and 10.9 seconds. The observed delay suggests timeout checks happen on an interval, so this mechanism isn’t suitable when timing must be precise.
Third, and most consequential, timing out doesn’t stop the vCenter operation. In an initial test, the workflow failed while the snapshot task continued and eventually created a snapshot that the workflow no longer cleaned up. The error handler should therefore receive the task as an input, check whether it is still running and cancel it if it is cancelable. If it can’t be cancelled, the handler should warn that follow up cleanup will be needed.
var info = task ? task.info : null;
if (info && info.state.value == "running") {
if (info.cancelable) {
task.cancelTask();
System.warn("Cancelled vCenter task " + info.key);
} else {
System.warn(
"Task " + info.key +
" is still running and cannot be cancelled. " +
"Remove the snapshot by hand when it finishes."
);
}
}
throw "Waiting event ended with an error after at most " +
timeoutSec + " s: " + errorCode;In the five second test, the error handler cancelled the still running task, then failed the workflow with Timeout on signal. The snapshot task showed as cancelled in vCenter, and the VM had no snapshot left. Not every vCenter task supports cancellation, so the handler needs a plan for those cases: wait for completion and clean up, or raise the unfinished task for someone to review.

Choose the wait method to fit the work
For tasks that finish in a few seconds, polling with vim3WaitTaskEnd is straightforward and its cost is small. For work that takes minutes, or when many workflows may wait at once, a trigger lets each run suspend until the task ends or the timeout is reached. A Waiting timer serves a different purpose: it suspends a run until a specified date and time, such as a scheduled check. See the TechDocs guidance for timer based long running workflows.
For vCenter task waits, create the trigger immediately before the Waiting event, bind trigger.ref, and check task.info.state after the run resumes. Set a timeout that fits the operation, and make the exception path account for the underlying task: the wait can expire while vCenter is still working.