Scheduling Airflow DAG at two differents times per day - cron

I want to launch a same DAG at 2 differents times in the same day without copying this one, for exemple I want to run it every day at 5:00 PM and 6:30 PM

I'm not super certain if it will work but you might want to try passing a cron string to the schedule argument of the DAG. Where the cron defines your two times.
I'm also not certain you'll be able to have 5:00 and 6:30 only though, as different minute / hours.
This is a handy site for validating cron expressions.

This means running at hours 5 and 6 at minute 30.
A problem would be if you wanna 5:00 and 6:30, I don't guess CRON does not handle such options

Related

Cron Job With Altering Behavior Depending on Hour

Is it possible to execute a Cron job such that between certain hours, it executes every 30 minutes, but other hours, only every 1 hour?
I was unable to figure this out using my basic Cron abilities.

How to run every 25 minutes every day from 9 AM to 5 PM in Quartz scheduler?

I am using the Quartz Scheduling and I've tried to create a trigger that starts every day at 9 AM until 5 PM, every 25 minutes. It should like that:
9:00, 9:25, 9:50, 10:15, 10:40, 11:05, etc
The final quarts expression looks like that:
0 0/25 9-17 * * ? *
But the execution looks like that:
9:00, 9:25, 9:50, 10:00, 10:25, 10:50, 11:00, etc
There is any way to reach this schedule:
9:00, 9:25, 9:50, 10:15, 10:40, 11:05, etc
or I should change quartz?
Thank you!
Actually this question is similar to Cron expression to be executed every 45 minutes SO question.
Cron expression will not allow you to do that as it defines the exact date and times, when a trigger must be fired. And setup like your actually means "fire every 25 minutes, starting at minute 0 of every hour".
You can achive what you want by using SimpleTrigger with .WithIntervalInMinutes(25) configuration.
SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a specific moment in time, or at a specific moment in time followed by repeats at a specific interval.
P.S. Your cron expression will work for 20 minutes (0 0/20 9-17 * * ? *), as 60 is a multiple of 20. Just in case changing interval is not critical to you)
P.S.2 To be honest you can use Cron expressions if setup few trigger for different intervals, but that is useless. Anyway look onto this SO answer

run cron job within a specific time range

How do i run a cron job everyday from 8:30 pm to 5:30 am(next day) during working hours at the interval of 1 hour. i tried everything from google but no thread meet my requirement due to time range including two days.
i believe this cron expression works: 0 30 0,1,2,3,4,5,20,21,22,23 1/1 * ? *
Use two crontab entries: one for 8:30pm-midnight, and one from 0030 to 0530.

Creating Cron Expression with of Days and Months Simultaneously

I simply want to create a cron expression that will execute a job after 'N' number of days. Where N can be any number greater than Zero.
So, It's alright if number is between 1 and 30. For Example Cron Expression to Execute Job after each
25 days at 11 AM will be:
0 0 11 1/25 * ? //'?' can only be specfied for Day-of-Month or Day-of-Week.
but if user exceeds this limit so it means we will have to execute job after 'M' months and 'D' days.
I am unable to understand how I can specify both day and month at the same time. Can anyone make me understand how I can create cron expression for this scenario. You may assume job to be execute after each '65' days
thanks for your time.
The short answer is that cron expressions don't support what you want to do. You'll need to pre-process the user's request and convert it into the appropriate cron expression, or implement your own timing routine, which could use cron behind the scene with some extra logic. Another suggestion is to put some restrictions on the user API that will only allow the user to enter cron friendly times like every month, every week, every 3 months, etc.

cron job between 8am and 8pm 4 times at specified intervals of time

i need to run a job 'x' times a day. job timing is every (say 'y' hours) between 8am and 8pm.
i read the documentation of cron between could not figure out how to place the "between times". any suggestion or a good tutorial should be really helpful.i could figure out this much.
Found this in a tutorial. I believe this will serve the requierment
SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
simpleTrigger.setStartTime(d);
simpleTrigger.setRepeatInterval(1000*60*60*24);
simpleTrigger.setRepeatCount(15);
simpleTrigger.setEndTime(new Date(ctime + 60000L));
simpleTrigger.setPriority(10);
scheduler.scheduleJob(jobDetail, simpleTrigger);
scheduler.start();
how could i modify the expression to serve my purpose.
You have a * in your example where you need to put the start/end hours:
0 8-20/y * * *
Where you replace y with the number of hours you want between runs should be fine. If you have some strange time like "1 hour and 15 minutes between runs", it's going to be a pain - probably just easier to calculate each time and enter it explicitly.
I don't know you can express this in cron expression.
However, you can use multiple Quartz triggers to serve this purpose.

Resources