How to control the execution of tasks

Task dependency using `assert like` helpers

If a task depends on another task value, or state value, or metadata value you can use assert like helpers. Execution will be stopped if such assert are triggered. Instead of a value, a message of why the task didn't return a value will be present in the task result:

@task(name="task-a")
def task_a(image_input: Image) -> bool:
    return True
    
@task(name="task-b")
def task_b(image_input: Image) -> bool:
    # If task-a not True, won't process further
    self.assert_task_is("task-a", True)
    # We can add custom message. Otherwise, a generic slug is sent
    self.assert_task_is_not("task-a", False, "Oh nooooo, task-a is False"
    return True

Available helpers are:

# Asserts based on the value of a task from a previous analysis
self.assert_state_is("task_group_name", "task_name", value)
self.assert_state_is_not("task_group_name", "task_name", value)

# Asserts based on the value of the work order metadata
self.assert_wo_metadata_is("key", value)
self.assert_wo_metadata_is_not("key", value)

# Asserts based on the value of the analysis metadata
self.assert_analysis_metadata_is("key", value)
self.assert_analysis_metadata_is_not("key", value)

# Assert checking if a task has a value and was therefore correctly executed
self.assert_task_has_value("task_name")

# Asserts based on the value of a task from that current analysis
self.assert_task_is("task_name", value)
self.assert_task_is_not("task_name", value)

# Asserts based on the key in the workspace
self.assert_workspace_key_is("key", value)
self.assert_workspace_key_is_not("key", value)

When an assert fails, it actually raises a TaskConformityError.

Exceptions

You can manually control the execution of task by raising workflow specific exceptions:

TaskConformityError

To prevent a task from returning a value, a TaskConformityError with an error message can be raised. This is used to notify a reason of why a task couldn't be analysed properly.

DataConformityError

To prevent a task from returning a value, a DataConformityError with an error message can be raised. This is used to notify there is Data Conformity related error. WIP, don't use this for now. Or warn us if you would want to.