Airflow using Cronitier

Viewed 635

I am trying to use Cronitier to schedule job a monthly job to run every 2 Tuesday. I tried below This is my partial script.

from croniter import croniter

cron = croniter("00 21 * * 2#2")

dag = DAG('recurring_job', catchup=False, default_args=default_args, schedule_interval=cron) But it didn't work. Would you please help me or give some reference.

2 Answers

You can just specify the cron string directly:

dag = DAG('recurring_job', schedule_interval="00 21 * * 2#2")

Airflow will translate that using croniter internally.

Airflow supports also datetime.timedelta object for schedule_interval, see Scheduling & Triggers:

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.

Together with start_date, it should work out without the usage of croniter:

dag = DAG('recurring_job', catchup=False, default_args=default_args, schedule_interval=datetime.timedelta(weeks=2), start_date = datetime(2020,11,3,21))
Related