How to schedule a airflow dag for multiple days?

30 views Asked by At

i'm trying to schedule a dag from 12pm on let's say 15/02/2024 to 12pm of 17/02/2024 and it runs every 3 hours, but when i'm using the following cron expression: 0 12/3 * * *

i have given the start date in the dag as 15/02/2024 and end date as 17/02/2024. The dag here runs from 12pm 15/02/2024 to 12am 16/02/2024 and it again starts from 12pm on 16/02/2024.

How can i make the dag also run from 12am-12pm 16/02/2024 with an interval of 3 hours?

1

There are 1 answers

0
vdolez On

The CRON instruction to use is the following 0 */3 * * * in conjunction with using an appropriate start_date and end_date.

DAG(
    dag_id="my_dag_name",
    start_date=datetime.datetime(2024, 2, 15, 12, 0),
    end_date=datetime.datetime(2024, 2, 17, 12, 0),
    schedule='0 */3 * * *',
    catchup=True,)

With this configuration, the DAG will generate DAG runs for every time period included between the start date and the end date, using a 3 hours interval.

Turning on catch up mode allows to run the DAG for the whole period once activated.

You can use tools such ascrontab.guru to design the CRON expression. You can click on the next button to have examples of the following executions.