Airflow- Using TriggerDAGRunOperator to trigger DAG of different schedule

I’m new to Airflow. I need to come up with a clean easy solution for DAG dependencies with different schedules.

I have DAG 1 running Daily and DAG 2 - Weekly. How do I use TriggerDAGRunOperator to trigger weekly DAG from Daily one?

DAG 1:

with DAG('DAG 1',
     schedule_interval='0 10 * * *'
     ) as dag:

TASK1 = BashOperator(task_id='TASK1',
                bash_command='sample')
TRG_TASK=TriggerDAGRunOperator(task_id='TRG_TASK',trigger_dag_id='DAG 2')

TASK1 >> TRG_TASK

DAG 2:

with DAG('DAG 2',
     schedule_interval='15 10 * * 5'
     ) as dag:

TASK1 = BashOperator(task_id='TASK1',
                bash_command='sample')

I know I can use ExternalTaskSensor Operator and mention timedelta, but it would become messy in long run.

Is there any easy/clean option with TriggerDAGRunOperator to check everyday if DAG 2 is indeed scheduled to run for that day then only trigger it else skip it on other days?

Thanks

I know this question is a bit old now, but you can remove the schedule from the second dag (make it None) and then in a branch operator check for day of week or days since last dag 2 run (or however you are determining the dag2 needs to run). If it is the day to run dag 2, return that task name. Otherwise, continue on as normal (I usually have an END task).

1 Like