Hello, quick question, I am using `trigger=any_fai...
# ask-community
m
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
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
Copy code
success = succeed(upstream_tasks=[do_something_important])
    failed_task = fail(upstream_tasks=[do_something_important])
    always_run(upstream_tasks=[do_something_important])
🙌 1
m
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
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.