获取所有气流叶节点/任务 [英] Get all Airflow Leaf Nodes/Tasks

查看:64
本文介绍了获取所有气流叶节点/任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一些我需要捕获所有叶子任务并向其添加下游依赖关系的东西,以使我们的数据库中的工作完成。有没有简单的方法可以找到Airflow中DAG的所有叶节点?

I want to build something where I need to capture all of the leaf tasks and add a downstream dependency to them to make a job complete in our database. Is there an easy way to find all the leaf nodes of a DAG in Airflow?

推荐答案

使用 upstream_task_ids downstream_task_ids @property 来自 BaseOperator

Use upstream_task_ids and downstream_task_ids @property from BaseOperator

def get_start_tasks(dag: DAG) -> List[BaseOperator]:
    # returns list of "head" / "root" tasks of DAG
    return [task for task in dag.tasks if not task.upstream_task_ids]


def get_end_tasks(dag: DAG) -> List[BaseOperator]:
    # returns list of "leaf" tasks of DAG
    return [task for task in dag.tasks if not task.downstream_task_ids]






类型注释 来自 Python 3.6 +

这篇关于获取所有气流叶节点/任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆