Cron & Time Intervals¶
You may set your DAG to run on a simple schedule by setting its schedule
argument to either a
cron expression, a datetime.timedelta
object,
or one of the Cron Presets.
from airflow.models.dag import DAG
import datetime
dag = DAG("regular_interval_cron_example", schedule="0 0 * * *", ...)
dag = DAG("regular_interval_cron_preset_example", schedule="@daily", ...)
dag = DAG("regular_interval_timedelta_example", schedule=datetime.timedelta(days=1), ...)
Cron Presets¶
For more elaborate scheduling requirements, you can implement a custom timetable.
Note that Airflow parses cron expressions with the croniter library which supports an extended syntax for cron strings. See their documentation in github.
For example, you can create a DAG schedule to run at 12AM on the first Monday of the month with their extended cron syntax: 0 0 * * MON#1
.
Tip
You can use an online editor for CRON expressions such as Crontab guru
preset |
meaning |
cron |
---|---|---|
|
Don’t schedule, use for exclusively “externally triggered” DAGs |
|
|
Schedule once and only once |
|
|
Run as soon as the previous run finishes |
|
|
Run once an hour at the end of the hour |
|
|
Run once a day at midnight (24:00) |
|
|
Run once a week at midnight (24:00) on Sunday |
|
|
Run once a month at midnight (24:00) of the first day of the month |
|
|
Run once a quarter at midnight (24:00) on the first day |
|
|
Run once a year at midnight (24:00) of January 1 |
|
Your DAG will be instantiated for each schedule along with a corresponding DAG Run entry in the database backend.