Quartz Cron expression with custom hours - cron

I want to write a quartz cron expression that will fire my trigger in the following times:
7:40 AM, 1 PM, 6 PM.
I know that I can do this:
0 0,40 7,13,18 ? * 2-6 (to run it MON - FRI every day in the month)
But the problem is that it will actually run at 7:00, 7:40, 13:00, 13:40, 18:00, 18:30.
Please show me a best practice to such issue.
Thanks,
Steve

Related

How to write cron expression to run a job that starts on Saturday and ends on Sunday?

I'm pretty new to using crontab. I have a requirement to schedule an airflow DAG that should run every hour starting at 21:00 on every Saturday and run till 04:00 on Sunday.
i.e it should run according to the below schedule:
21:00 on Saturday(18th June 2022)
22:00 on Saturday(18th June 2022)
23:00 on Saturday(18th June 2022)
00:00 on Sunday(19th June 2022)
01:00 on Sunday(19th June 2022)
02:00 on Sunday(19th June 2022)
03:00 on Sunday(19th June 2022)
04:00 on Sunday(19th June 2022)
The next iteration should start on Saturday(25th June 2022) at 21:00
I tried using the below expression but it's showing invalid:
0 21-23,0-4 * * 6-0
You cannot have multiday spanning ranges set in single crontab entry because crontab file syntax is very limited and it simply does not support that. In your current form you would end up having job run also every Sunday 21:23 hrs too. The simplest workaround is to create two separate entries: first one for Saturday and 2nd one for Sunday, so there's no way of any overlap and ambiguition:
0 21-23 * * 6
0 00-04 * * 0
Airflow allow more flexible scheduling than just cron expression.
While Marcin answer is correct the context of the question is scheduling DAG on Airflow so I'll provide the solution for this case from Airflow side.
Since Airflow 2.2.0 a new feature was added: AIP-39 Richer scheduler_interval
A new concept of Timetable is available which allows you among another things to handle use cases that don't fit into a single cron expression. To do that you can follow Customizing DAG Scheduling with Timetables. In essence you register a Timetable via plugin that returns the values of when the DAG should be scheduled, so if you can write a Python function that can generate the scheduling logic Airflow can use this to schedule your DAG. You can see example for use function in this doc. In simple words if you can write a Python function that will return the next date according to your logic then you can use Timetable for the scheduling.

Cron Scheduler - every quarter end third Sunday # 3:30 AM CST

Actually I am trying to schedule an application , which has to be run at
Cron expression to run application job for every end of quarter on 3rd Sunday at 3:30 AM CST
currently am using 0 */10 * ? * * - which runs for every ten minutes.
when I search on online ,this link https://crontab.guru/every-quarter
0 0 1 */3 * this would run for every quarter I guess.
But for my requirement , which I stated above, am not sure actually.
but , i referred some of the previous questions and some trial and error , I reached something like this 30 3 15-21 */3 SUN but am not sure. Please give your thoughts
OK .. for spring scheduler cron expression, below is my best bet
0 30 03 15-21 3,6,9,12 SUN
should work i think. tested partially. since, the above expression will run only on june.

Cron Expression - Start at 10:20 and execute each 10min until 19:00

I have a case in which I'm migrating some tasks from Windows to a platform and we are using cron expressions to replace the Windows Scheduler.
Today we have something in Windows like At 10:20 AM every weekday, every 10 minutes for 9 hours. I'm trying to replace it with chron but I couldn't achieve it so far.
The closest I got is 0 20/10 10-19 * * MON-FRI. The thing is on this cron, it won't execute at 11:00, 12:00 and so on. We have a specific case in which we don't want it to execute at 10:00 AM.
The only option I found is to execute at 10:00AM and put some condition to validate it. Is it possible to achieve this result with only chron?
Thanks!
You can do it with cron, but you'll need to break it up into two schedules.
20/10 10 * * MON-FRI
and
*/10 11-19 * * MON-FRI
Btw, if this is cron on unix, there is no field for seconds.

Cron expression for only for wednesday every after 2 hours

java - Spring, i want to crate cron expression to run every after 2 hours only on Wednesday till day end
0 0 0/2 * * WED *
mean cron should trigger every wednessday only for these times 2am, 4am, 6am, 8am,10am, 12pm, 2pm,4pm, 6pm, 8pm, 10pm, 12pm
i don't have time long to wait and test can some one please confirm is it correct ?
Even though it is way to late i like to answer the question for other users.
Your CronExpression is invalid. You can check this here or here. The problem is: You cannot specify a day_of_month AND a day_of_week.
Cause you are setting a day_of_week you should skip day_of_month with a "?". Solution should be: 0 0 0/2 ? * WED *

how to build cron expression for hours and minutes

i want a cron expression for a schedule which runs for every 2hr 10 min and output am expecting is
2:00
4:10
6:20
i tried 0 0/2 0/2 * * ? for that and the output was like this
Thursday, November 1, 2012 12:50 PM
Thursday, November 1, 2012 12:52 PM
Thursday, November 1, 2012 12:54 PM
source-http://www.cronmaker.com
Thanks in advance..
I too had searched a lot previous to run a cron for every (> 60 ) minutes, but was not able to find any solution.
Best way to implement the solution to your problem, is to write your own script that would check the script's last run which you can handle in any way (check timestamp, log the last run somewhere, etc) and would run the required job if only the time conditions are met.
Then put a cron to call this wrapper script every 10 mins (in your case), as this would ensure, it would get checked for each of the time you would have expected the original final job to run.
Hope this helps.

Resources