Waiting for a task to complete

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.

  1. Create the new task
  2. 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).
  3. Sleep during 1 second
  4. Using the task identifier obtained in 2, execute a task query
  5. Inspect the returned object, and obtain the value of the field state
  6. If state is pending, return to 3
  7. If state is completed, obtain the value of fields result and result_msg
  8. Inspect result and result_msg and act accordingly

Â