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

None

Don’t schedule, use for exclusively “externally triggered” DAGs

@once

Schedule once and only once

@continuous

Run as soon as the previous run finishes

@hourly

Run once an hour at the end of the hour

0 * * * *

@daily

Run once a day at midnight (24:00)

0 0 * * *

@weekly

Run once a week at midnight (24:00) on Sunday

0 0 * * 0

@monthly

Run once a month at midnight (24:00) of the first day of the month

0 0 1 * *

@quarterly

Run once a quarter at midnight (24:00) on the first day

0 0 1 */3 *

@yearly

Run once a year at midnight (24:00) of January 1

0 0 1 1 *

Your DAG will be instantiated for each schedule along with a corresponding DAG Run entry in the database backend.

Was this entry helpful?