Reputation: 311
Is it recommended, and what is the best way to trigger DAG A from DAG B with some configs passed to DAG A from DAG B?
Upvotes: 1
Views: 2752
Reputation: 121
You can use TriggerDagRunOperator.
In the first DAG, insert the call to the next one as follows:
trigger_new_dag = TriggerDagRunOperator(
task_id=[task name],
trigger_dag_id=[trigered dag],
conf={"key": "value"},
dag=dag
)
This operator will start a new DAG after the previous one is executed.
Now you can download some configs passed to DAG A from DAG B by (for example) PythonOperator
def _take_data(**context):
DAGA_data = context["dag_run"].conf
download_data_from_DAGA = PythonOperator(
task_id='download_data_from_DAGA ',
provide_context=True,
python_callable=_take_data,
dag=dag,
)
Documentation: https://airflow.apache.org/docs/apache-airflow/stable/_api/airflow/operators/trigger_dagrun/index.html
Upvotes: 2