Search code examples
pythonairflow

How to configure Airflow dag to run at specific time on daily basis?


How to configure the Airflow dag to execute at specified time on daily basis no matter what happens, something exactly like crons.

I know that similar behaviour could be obtained using TimeSensor, but in this case it depends upon the sensor tasks and which might conflict with the dag execution time.

Example: With sensor approach if I have sensor to run at 0 hour 15th minutes but if dag is executed at later then my task is delayed, so even for the sensor approach I need to make sure that the Dag is executed on right time.

So how to make sure that Dag is executed at specified time?


Solution

  • To start a DAG for example everyday on 2:30 AM in the morning you can do the following:

    DAG(
       dag_id='dag_id',
       # start date:28-03-2017
       start_date= datetime(year=2017, month=3, day=28),
       # run this dag at 2 hours 30 min interval from 00:00 28-03-2017
       schedule_interval='30 2 * * *')
    

    Before configuring the schedule the interpretation of the cron interval can verified and tested here: https://crontab.guru/