Suman Banerjee
Suman Banerjee

Reputation: 23

schedule airflow 2 times in a day

I am new to Airflow and wanted to ask how to schedule a airflow workflow 2 times in a day e.g. I need to schedule a airflow dag at 10:00 am and 7:00 pm from 2022-03-24, so after some research I think it will be like

interval='0 10,19 * * *'
date='2022-03-23'
schedule_interval=interval
start_date=date

is my understanding is correct ?

Thanks in advance,

Upvotes: 2

Views: 6624

Answers (2)

SudhakarH
SudhakarH

Reputation: 551

Yes, your understanding is correct. Instead of using extra variables you can feed direct values while creating DAG object.

from datetime import datetime
from airflow import DAG
with models.DAG(
      dag_id='my_dag',
      schedule_interval='0 10,19 * * *',
      start_date=datetime(2022, 3, 23),
      catchup=False
) as dag:

You can also provide default_args,retries,concurrencies, etc depends on your dag behaviour.

Upvotes: 2

Elad Kalif
Elad Kalif

Reputation: 15931

Yes. You will need to create DAG object as:

from datetime import datetime
from airflow import DAG
dag = DAG(dag_id='my_dag',
          schedule_interval='0 10,19 * * *',
          start_date=datetime(2022, 3, 23),
          catchup=False)

Note: if you want your first run to start on 2022-03-24 at 10:00 then your start_date needs to be datetime(2022, 3, 23, 19, 0) this is because Airflow schedule runs at the end of the interval. See this answer for more information about it.

Upvotes: 4

Related Questions