Anchit Jain
Anchit Jain

Reputation: 11

Airflow DAG scheduling

How can I schedule my Airflow DAG on "Last day of the month" and on "Last working day of the month"

Note - the scheduling should take care if the month has 28/29/30/31 days and if it is leap year or not.

Upvotes: 0

Views: 1077

Answers (2)

Berk Sudan
Berk Sudan

Reputation: 161

EDIT: According to crontab.cronhub.io, last week day can be defined asLW. That said, if you want to cover both the last day and last week-day of the month, you should use a crontab expression like 00 08 L,LW * *. Note that, I did not try this and still not completely sure.

I am not sure how you can define "last working day of the month" but you can define "last day of the month" using a crontab expression like the following:

 00 08 L * * # Run at 08.00 AM on the last day of the month, every month

In DAG File:

 with DAG(
     dag_id='tester',
     schedule_interval='00 08 L * *', # Here
     ...
 ) as dag:
        ...

Additionally,

You can define more than a day using comma, like the following expression:

 00 08 1,L * * # Run at 08.00 AM on the last day and first day of the month, every month

Upvotes: 1

Brackl1
Brackl1

Reputation: 89

The Airflow schedule interval parameter expects a cron expression. This is well described in the Airflow documentation.

https://airflow.apache.org/docs/stable/scheduler.html

Although cron does not explicitly support "the last day of the month" a potential workaround is to have your DAG run as soon as possible on the first day of every month.

For example to have your DAG run at 00:00 on the first day of every month set the schedule interval to:

0 0 1 * *

Upvotes: 0

Related Questions