Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule a DAG in airflow to run every 5 minutes

Tags:

airflow

I have a DAG in airflow and for now it is running each hour (@hourly). Is it possible to have it running each 5 minutes ?

like image 693
bsd Avatar asked Aug 15 '17 08:08

bsd


People also ask

How do you schedule a DAG in Airflow?

Note that DAG Runs can also be created manually through the CLI while running an airflow trigger_dag command, where you can define a specific run_id . The DAG Runs created externally to the scheduler get associated to the trigger's timestamp, and will be displayed in the UI alongside scheduled DAG runs .

How do I schedule daily DAG?

Setting a cron-based schedule​ You can pass any cron expression as a string to the schedule parameter in your DAG. For example, if you want to schedule your DAG at 4:05 AM every day, you would use schedule='5 4 * * *' . If you need help creating the correct cron expression, see crontab guru.

What is Airflow data interval?

Each DAG run in Airflow has an assigned “data interval” that represents the time range it operates in. For a DAG scheduled with @daily , for example, each of its data interval would start each day at midnight (00:00) and end at midnight (24:00).


2 Answers

Yes, here's an example of a DAG that I have running every 5 min:

dag = DAG(dag_id='eth_rates',
          default_args=args,
          schedule_interval='*/5 * * * *',
          dagrun_timeout=timedelta(seconds=5))

schedule_interval accepts a CRON expression: https://en.wikipedia.org/wiki/Cron#CRON_expression

like image 131
Mike Avatar answered Oct 21 '22 23:10

Mike


The documentation states:

Each DAG may or may not have a schedule, which informs how DAG Runs are created. schedule_interval is defined as a DAG arguments, and receives preferably a cron expression as a str, or a datetime.timedelta object.

When following the provided link for CRON expressions it appears you can specify it as */5 * * * * to run it every 5 minutes.

I'm not familiar on the matter, but this is what the documentation states.

like image 37
Jan_V Avatar answered Oct 21 '22 22:10

Jan_V