6

In Airflow 1.10.10, when a disabled DAG is enabled by pressing the button to change it's state from Off to On, the DAG will always run once before the next scheduled run time.

enter image description here

Is it possible to set a DAG to be enabled, but not make its first run until the next time it is scheduled to be run?

Currently, I need to quickly kill the DAG run after I toggle its state to be On.

Athena Wisdom
  • 6,101
  • 9
  • 36
  • 60

2 Answers2

1

You should set the start_date (which is a datetime) to value after now.

According to the docs

  • the first DAG Run is created based on the minimum start_date for the tasks in your DAG.
  • Subsequent DAG Runs are created by the scheduler process, based on your DAG’s schedule_interval, sequentially.
Oleg Pavliv
  • 20,462
  • 7
  • 59
  • 75
  • Is it possible to dynamically set the `start_date` to after `now` without [the problems associated with using dynamic `start_date` values](https://airflow.apache.org/docs/stable/faq.html#what-s-the-deal-with-start-date)? The goal is to not have to manually set `start_date` and still avoid having the DAG run instantly when it is enabled/resumed. – Athena Wisdom Jun 18 '20 at 14:29
  • Yes, it can be a problem. I didn't think about it. You may need to set it somewhere externally, e.g. env var and read from the DAG – Oleg Pavliv Jun 18 '20 at 17:05
1

If it is daily task - set start date as below : This will prevent your DAG from running immediately after enabling.

default_args = {
    'start_date': airflow.utils.dates.days_ago(1) 
}

If it is a monthly task - set start date as below :

default_args = {
    'start_date': airflow.utils.dates.days_ago(30) 
}
Afz Abd
  • 423
  • 3
  • 19