Get all nodes / tasks for leaf airflow
I want to create something where I would need to record all sheet tasks and add a downstream dependency to them to make the job complete in our database. Is there an easy way to find all DAG leaf nodes in Airflow?
+4
Ace haidrey
source
to share
1 answer
Use upstream_task_ids
and fromdownstream_task_ids
@property
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]
Type-Annotations
of Python 3.6+
0
y2k-shubham
source
to share