I have a task_a that I want to use in DAG_1 and DAG_2. Is this possible in airflow?
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)
)
Is this possible?
you could always do something with partial
and then assign it to 2 different dags:
from functools import partial
task_template = partial(SomeOperator, some_id='id', some_command='cmd')
task_template(dag=dag1)
task_template(dag=dag2)
you could also just create a function that does it:
def create_task(dag):
return SomeOperator(some_id='id', some_command='cmd', dag=dag)
for d in (dag1, dag2):
create_task(d)
As per Current Design no.
Tasks are part of DAG's. Each DAG run creates a task instance.
This is to keep the framework's housekeeping simple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With