vCO Workflow Action to Wait for a vCloud Task to Complete

The following is the script to wait for a vCloud task to complete

 

if (objVclTask != null)
{
	while (true)
	{
		try
		{
			objVclTask.updateInternalState();
		}
		catch (objException)
		{
			System.error(objException.description);
		}

		if (objVclTask.status == VclTaskStatusType.SUCCESS.value)
		{
			break;
		}
		else if (objVclTask.status == VclTaskStatusType.CANCELED.value)
		{
			throw "===== Task " + objVclTask.name + " has been CANCELLED";
		}
		else if (objVclTask.status == VclTaskStatusType.ABORTED.value)
		{
			throw "===== Task " + objVclTask.name + " has been ABORTED";
		}
		else if (objVclTask.status == VclTaskStatusType.ERROR.value)
		{
			var strError = "Unknown Error";

			if (objVclTask.error != null)
			{
				strError = objVclTask.error;
			}

			throw "===== Task " + objVclTask.name + " has an ERROR: " + strError;
		}

		System.sleep(1000);
	}
}

Leave a Reply