Recognizing succeeded vs failed tasks w/ the Task Management API

The documentation for the Task Management API shows how to get the status of a task as json. However, it does not indicate how to tell from that json whether a task has completed successfully. I don't want to block on the task with wait_for_completion; I just want to write a function that returns whether a given task has finished successfully, failed, or is still running.

I have experimented with forcing tasks to fail to see how the failure is recorded in the status, and sometimes I see a a field called "error" in the toplevel json while other times I see field called "failures" within a field called "response" (and I have never seen both).

So as far as I can tell, in order to tell from the status json that the task has succeeded, I need to verify that:

  1. The 'completed' field of the json exists and is true
  2. The 'error' field of the json does not exist
  3. The 'response.failures' field does not exist or is an empty string
  4. The 'response.canceled' field does not exist

Is there a simpler way to check whether a task has finished successfully? If I'm running a task with subtasks (e.g., reindex with slices), do I need to do these checks for every subtask, or can I just look at the status json for the toplevel task (the task ID returned by the reindex API)?

3 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.