Python 是否可以在气流中的多个DAG中使用单个任务?

Python 是否可以在气流中的多个DAG中使用单个任务?,python,airflow,Python,Airflow,我有一个任务a,我想在DAG_1和DAG_2中使用。这在气流中可能吗 task_a = SomeOperator( task_id='some_id', bash_command='some_command', #instead of just dag= DAG_1 # I want to assign this task to multiple dags #dag=assign_multiple_dags_here(DAG_1 and DAG_2) ) 这可能吗?根据当前设计编号 任务是DA

我有一个任务a,我想在DAG_1和DAG_2中使用。这在气流中可能吗

task_a = SomeOperator(
task_id='some_id',
bash_command='some_command',
#instead of just
dag= DAG_1 # I want to assign this task to multiple dags
#dag=assign_multiple_dags_here(DAG_1 and DAG_2)
)

这可能吗?

根据当前设计编号

任务是DAG的一部分。每次DAG运行都会创建一个任务实例


这是为了保持框架的内务管理简单

您始终可以使用
部分
执行某些操作,然后将其分配给两个不同的DAG:

from functools import partial
task_template = partial(SomeOperator, some_id='id', some_command='cmd')
task_template(dag=dag1)
task_template(dag=dag2)
您也可以创建一个函数来执行此操作:

def create_task(dag):
    return SomeOperator(some_id='id', some_command='cmd', dag=dag)

for d in (dag1, dag2):
    create_task(d)

我投了赞成票,赞成你提出的使用部分替代品的建议。我喜欢把它当作一种工作。