如果其他任务失败,Python 完美跳过任务

发布于 2025-01-20 08:25:26 字数 85 浏览 2 评论 0原文

我的工作流程中有两个任务 A 和 B,如果任务失败,我想跳过 B,请问有什么办法吗? @任务 一个(): 经过 乙(): 经过 Flow("") 作为流程:

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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2025-01-27 08:25:26

如果上游任务A失败,Perfect的默认行为不是运行任务B。但是,这些任务必须通过upstream_tasks关键字明确地依赖对方,或者通过彼此之间的数据隐式。您还可以使用触发者控制这种行为。

如何设置依赖项的示例:

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])

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])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文