vRO comes with builtin actions for waiting for a VC:Task (vCenter Task). However this (as all “builtin” actions comes without any form of errorhandling.)
This is an example on how to include error handling (and note: This is now a workflow)
Input parameter:
[Number]MaxWaitTime = Number of seconds for maximum wait before we say the task timed out.
[VC:Task]Task = Task to wait for completion.
Output parameters:
[String]TaskResult = “ERROR”,“TIMEOUT” or “OK” (check for this result)
[String]TaskError = Error Description if TaskResult = “ERROR”
var timeout = MaxWaitTime; if (timeout == 0) { timeout = 60; // 60 Seconds minimum } var polling = 5; // Check Every 5 second.. TaskError = ""; // Blank by Default. if (Task != null && (Task instanceof VcTask)) { System.log("WaitForTask started. Task: "+Task.name +"("+Task.info.name+") on: "+Task.info.entityName); while (true) { if (Task.info.state ==VcTaskInfoState.error) { TaskResult= "ERROR"; TaskError = Task.info.error.message; break; } else if (Task.info.state ==VcTaskInfoState.running) { System.log("Task still running..."); timeout -= polling; System.sleep(polling * 1000); } else if (Task.info.state ==VcTaskInfoState.queued) { System.log("Task is queued..."); timeout -= polling; System.sleep(polling * 1000); } else if (Task.info.state ==VcTaskInfoState.success) { TaskResult = "OK"; break; } if (timeout <= 0) { System.log ("TaskWait timed out..."); TaskResult = "TIMEOUT"; break; } } System.log("Task Start Time: "+Task.info.startTime); System.log("Task Queue Time: "+Task.info.queueTime); try { // Note: If task failed, the completion time will not exists. System.log("Task Completion Time: "+Task.info.completeTime); } catch (exception) { // Do Not care... } } else { // Task was null TaskResult = "ERROR"; TaskError ="NULL value for Task to wait for." }