flexVDI's Task system is asynchronous. That is, when you create a new task, Manager will immediately answer, without waiting for the new task to end.
Sometimes, it could be useful, or even necessary for an external script or program, to wait for the end of a certain task. For those cases, we recommend to follow this protocol.
- Create the new task
- Inspect the TaskResult object, immediately returned by Manager, and if status is OK (that is, the task was successfully created), store the contents of the field message (this is the task identifier).
- Sleep during 1 second
- Using the task identifier obtained in 2, execute a task query
- Inspect the returned object, and obtain the value of the field state
- If state is pending, return to 3
- If state is completed, obtain the value of fields result and result_msg
- Inspect result and result_msg and act accordingly