https://prefect.io logo
Title
m

Michael Z

08/22/2022, 7:24 PM
Hello, quick question, I am using
trigger=any_failed
in my task. But I really only want to do something if the previous task has failed, and not consider all upstream tasks. Can someone point me in the right direction?
1
r

Rob Freedy

08/22/2022, 7:34 PM
Hey Michael!! I would recommend looking at this discourse post on how to trigger downstream tasks based on an upstream task's state. You can define a subset of tasks as an upstream task and do something based on it's state from there: https://discourse.prefect.io/t/how-can-i-trigger-downstream-tasks-based-on-upstream-task-s-state/106
success = succeed(upstream_tasks=[do_something_important])
    failed_task = fail(upstream_tasks=[do_something_important])
    always_run(upstream_tasks=[do_something_important])
🙌 1
m

Michael Z

08/22/2022, 9:28 PM
Hi @Rob Freedy thanks, if I could expand this example (Prefect 1.0) a little bit though, what if we had another task before
do_something_important
called
do_something_important_before
and this passes its output to
do_something_important
so it is still upstream. I would like to trigger only if
do_something_important
fails.
r

Rob Freedy

08/23/2022, 1:07 PM
As shown in the example, you could use the
trigger=all_finished
in the task decorator of the
do_something_import
task and then have something like
task_a_result = task_a(upstream_tasks=[do_something_important])
in the next task.