ahajib
ahajib

Reputation: 13510

Are airflow monthly dags delayed by a day or a month?

I am trying to set an airflow dag that runs on second day of each month. Based on my research, the schedule interval should be set to:

schedule_interval = '0 0 2 * *'

Now what worries my is the stuff discussed in airflow documentation. Based on what's discussed there:

Note that if you run a DAG on a schedule_interval of one day, the run stamped 2016-01-01 will be trigger soon after 2016-01-01T23:59. In other words, the job instance is started once the period it covers has ended.

Let’s Repeat That The scheduler runs your job one schedule_interval AFTER the start date, at the END of the period.

Does this mean that for monthly dags, everything will be delayed by one month? So for example the 2020-11-02 job will run on 2020-12-01 2359? If yes, how can I make sure that it runs exactly when it's supposed to?

Upvotes: 2

Views: 1260

Answers (1)

Philipp Johannis
Philipp Johannis

Reputation: 2946

Your interpretion is right, the DAG Run with execution_date=2020-11-02 will be triggered approximately on 2020-12-01 23:59. However, I think you don't need to be worried that the DAG is delayed or something, it still has a monthly schedule and will run every month. You rather need to take this logic into account when running a operator.

You can also simply work with other variables if you don't want to adapt the logic, for whatever reason:

{{ next_execution_date }} - the next execution date.

Upvotes: 3

Related Questions