Josh
Josh

Reputation: 107

Combine two cron-scheduling intervals in a single DAG

Rewrite of the question:

Using , I would like to schedule a process to run every two hours from 2 till 10 am and a single time at 22:30. The schedule_interval parameter accepts a cron-expression, but it is not possible to define a single cron-expression to achieve the above scheduling. Currently, I did:

dag = DAG(process_name, schedule_interval='30 2,4,6,8,10,12,14,16,18,20,22,23 * * *', default_args=default_args)

But this will execute the process every 30 minutes past the hour, and this every 2 hours from 2 till 23.

Is there a way I can combine two cron-schedules in Airflow?

0 2-10/2 * * *
30 22 * * *

Original question:

I have 2,4,6,10,12,14,16,18,20,22 00 * *

I need to have 23, 30 in my schedule, but I don't want 2-22 to be run at the 30 min interval.

Upvotes: 2

Views: 2746

Answers (2)

Elad Kalif
Elad Kalif

Reputation: 15961

You can't use two cron expressions for the same DAG (Might change in the future if PR: Add support for multiple cron expressions in schedule_interval is accepted)

Starting Airflow >=2.2.0: It is possible to get custom time based triggering using custom Timetable by customizing the DAG scheduling to match what you expect. To do so you need to define the scheduling logic by implementing next_dagrun_info and infer_manual_data_interval functions - Airflow will leverage this logic to schedule your DAG. You can view an example can be found here.

Upvotes: 1

Josh
Josh

Reputation: 107

So, I realized, it is not possible!

Upvotes: 1

Related Questions