Enhanced Depends Logic¶
v2.9 and after
Previous to version 2.8, the only way to specify dependencies in DAG templates was to use the
dependencies field and
specify a list of other tasks the current task depends on. This syntax was limiting because it does not allow the user to
specify which result of the task to depend on. For example, a task may only be relevant to run if the dependent task
succeeded (or failed, etc.).
To remedy this, there exists a new field called
depends, which allows users to specify dependent tasks, their statuses,
as well as any complex boolean logic. The field is a
string field and the syntax is expression-like with operands having
<task-name>.<task-result>. Examples include
task-3.Daemoned. The full list of
available task results is as follows:
||Task Succeeded||Task finished with no error|
||Task Failed||Task exited with a non-0 exit code|
||Task Errored||Task had an error other than a non-0 exit code|
||Task Skipped||Task was skipped|
||Task Omitted||Task was omitted|
||Task is Daemoned and is not Pending|
For convenience, if an omitted task result is equivalent to
(task.Succeeded || task.Skipped || task.Daemoned).
depends: "task || task-2.Failed"
is equivalent to:
depends: (task.Succeeded || task.Skipped || task.Daemoned) || task-2.Failed
Full boolean logic is also available. Operators include:
depends: "(task-2.Succeeded || task-2.Skipped) && !task-3.Failed"
In the case that you're depending on a task that uses
withItems, you can depend on
whether any of the item tasks are successful or all have failed using
.AllFailed, for example:
depends: "task-1.AnySucceeded || task-2.AllFailed"
This feature is fully compatible with
dependencies and conversion is easy.
To convert simply join your
dependencies: ["A", "B", "C"]
is equivalent to:
depends: "A && B && C"
Because of the added control found in
dag.task.continueOn is not available when using it. Furthermore,
it is not possible to use both
depends in the same task group.