Python prefect skip task if others failed

1.3k Views Asked by At

I have two tasks A and B in my workflow and I want to skip B if task failed,any idea please? @task A(): Pass B(): Pass Flow("") as flow:

1

There are 1 best solutions below

1
On BEST ANSWER

Prefect's default behavior is not to run task B if upstream task A fails. But those tasks must depend on each other either explicitly via the upstream_tasks keyword or implicitly by passing data between each other. You can also use triggers to control this behavior.

Example of how you can set dependencies:

from prefect import task, Flow

@task
def task_1():
    pass

@task
def task_2():
    pass

@task
def task_3():
    pass

with Flow("flow_with_dependencies") as flow:
    t1 = task_1()
    t2 = task_2(upstream_tasks=[t1])
    t3 = task_3(upstream_tasks=[t2])