Skip to content Skip to sidebar Skip to footer

Apache Airflow Scheduler Does Not Trigger DAG At Schedule Time

When I schedule DAGs to run at a specific time everyday, the DAG execution does not take place at all. However, when I restart Airflow webserver and scheduler, the DAGs execute on

Solution 1:

Your issue is the start_date being set for the current time. Airflow runs jobs at the end of an interval, not the beginning. This means that the first run of your job is going to be after the first interval.

Example:

You make a dag and put it live in Airflow at midnight. Today (20XX-01-01 00:00:00) is also the start_date, but it is hard-coded ("start_date":datetime(20XX,1,1)). The schedule interval is daily, like yours (3 2 * * *).

The first time this dag will be queued for execution is 20XX-01-02 02:03:00, because that is when the interval period ends. If you look at your dag being run at that time, it should have a started datetime of roughly one day after the schedule_date.

You can solve this by having your start_date hard-coded to a date or by making sure that the dynamic date is further in the past than the interval between executions (In your case, 2 days would be plenty). Airflow recommends you use static start_dates in case you need to re-run jobs or backfill (or end a dag).

For more information on backfilling (the opposite side of this common stackoverflow question), check the docs or this question: Airflow not scheduling Correctly Python


Solution 2:

Check the following:

  1. start_date is a fix time in the past(don't use datetime.now())
  2. if you don't want to run the historical data, use catchup=false
  3. to set a specific time for DAG to run (e.g hourly, monthly, daily, at a specific time), try using https://crontab.guru/#40_21_*_*_* to write what you need.
  4. If you think you have 1, 2, 3 steps all correct but the DAG is not running. Or the DAG can run every xx minutes, but failed to trigger even once in a daily interval, try create a new python file, copy your DAG code there, rename it so that the file is unique and then test again. It could be the case that airflow scheduler got confused by the inconsistency between previous DAG Runs' metadata and the current schedule.

Hope this helped!


Solution 3:

From the schedule your DAG should run everyday at 02:03 AM. My suspicion is the start_date might be impacting it. Can you hardcode that to something like 'start_date': datetime.datetime(2016, 11, 01) and try.


Solution 4:

Great answer apathyman. It helped me a lot to understand. I was using days_ago(0) and once I changed it to days_ago(1), scheduler started triggering.


Post a Comment for "Apache Airflow Scheduler Does Not Trigger DAG At Schedule Time"