Handling Failure using Failure Task/Node
The failure task feature enables you to designate a specific task to execute in the event of a failure within your workflow.
This is useful when you want to handle a failure in a specific way, such as retrying the task or sending an email notification or cleaning up the resources after a failure.
Important Note: Failure task or function accepts an optional err
parameter
which is an instance of FlyteError
. To use the FlyteError, you will need the
truefoundry version to be greater than or equal to 0.9.1 and the name of the
parameter should be err
only.
How to use Failure Task/Node
- let’s say we have a workflow with a task that fails
- In the above example, we have defined two task functions
normal_task
andfailure_task
. One is a normal task that will fail and the other is a failure task that will be executed in the event of a failure.
The failure task function input parameters should be completely same as the workflow function parameters else it will raise an error.
-
Failure task function also accepts an optional
err
parameter which is an instance ofFlyteError
which you can import fromtruefoundry.workflow
and this will contain the error message or stack trace of the failure. -
So this workflow will execute the
normal_task
and if it fails, thefailure_task
will be executed
In this way you can handle the failure of a task in a workflow.