Function: Wait for a vCloud Task to Complete

by Simon Sparks · 1 November 2025

To use this function add it to the class library file named vCloudService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCloudService.ts

Description: Orchestrator Function wait for a vCloud task to complete

Function serverFindAllForType

private WaitForVclTask(objVclTask: VclTask, intPollRate: number = 1): void {
    if (objVclTask != null) {
        while (true) {
            try {
                objVclTask.updateInternalState();
            }
            catch (objException) {
                this.objLogger.info(objException.description);
            }

            if (objVclTask.status === VclTaskStatusType.SUCCESS) {
                break;
            }
            else if (objVclTask.status === VclTaskStatusType.CANCELED) {
                throw "===== Task " + objVclTask.name + " has been CANCELLED";
            }
            else if (objVclTask.status === VclTaskStatusType.ABORTED) {
                throw "===== Task " + objVclTask.name + " has been ABORTED";
            }
            else if (objVclTask.status === VclTaskStatusType.ERROR && objVclTask.error === null) {
                throw "===== Task " + objVclTask.name + " has an unknown ERROR";
            }
            else if (objVclTask.status === VclTaskStatusType.ERROR && objVclTask.error !== null) {
                throw "===== Task " + objVclTask.name + " has an ERROR: " + objVclTask.error;
            }

            System.sleep(intPollRate * 1000);
        }
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like