How to execute a cron expression for every 2.5 min - cron

I want to create a cron expression which will run the scheduler every 2.5 min of every hour. e.g. 2.5min, 5.0min, 7.5min, 10.0min etc. of every hour.
I am using Spring to create the scheduler. I tried various combination but nothing worked. One of them is as below but it is not working.
#Scheduled(cron = "*/30 */2 * * * *")
Thanks in advance.

That should works for you
0 0/5 0 ? * * *
30 2/5 0 ? * * *
At second :00, every 5 minutes starting at minute :00, at 00am, of every day
At second :30, every 5 minutes starting at minute :02, at 00am, of every day
You are right in this case you need to schedule your task twice using expression like on example.

There is a danger of becoming fixated on the 30 seconds. My problem was that I needed to check 18000 records for updates every month ~ 1 record every 2.5 minutes. I spent too much time trying techniques to run a job at exactly 02:32:30 before I realised that accuracy was not important.
In my situation, I realised I could execute every 2 minutes, updating my full database every 25 days instead of every 31 days.
Alternatively, I could have had 2 cron jobs running every 5 minutes. First, a 2-minute gap, followed by a 3-minute gap.
02:30 02:32 02:35 02:37 02:40 02:42 02:45 02:47
My point is that when the cron job is live, it runs unseen. Obviously, everyone has their own specific problem, but before introducing complexity, consider if it is necessary. As long as the job executes, does it really matter the exact time it ran?

Related

How do I write a cron which run only on any hour and half (xx:30)

How to write a cron which run only on any hour and half (xx:30) ?
For example it would run only at 00:30, 01:30, 02:30, on so on until 23:30.
The first field in a crontab entry is the minutes. You want your job to run whenever the "minutes" part of the current time equals 30, so you need a 30 in the first field. You want it to run at such a time regardless of what the hours, days, or months are, so you put * in the remaining fields.
30 * * * * /my/job

Need Cron expression to trigger job for every 90 minutes in AWS Glue

In AWS glue service there is an option to trigger job by custom CRON expression. Before i used this (0/2 * * ? *) cron expression to trigger job for every 2 hours.
Now I need to change the cron expression to trigger every 90 minutes, i.e for every 1 and a half hour. I tried with many cron expressions but that did not triggered for every 90 minutes. Even if i give for 90 minutes, it trigged for every 1 hour.
Can anyone help me out by providing the correct cron expression to trigger job for every 90 minutes ?
You can use the following pattern which was based on Bill Weiss' answer on Server Fault. It was modified to comply with the unique syntax AWS uses (reference here):
0 0-21/3 * * ? *
30 1-22/3 * * ? *
You'll have to define two separate Glue Triggers to accomplish this, each with the same job settings.
If curious, the syntax reads:
Run every 0th minute for every third hour for 0-21 hours
Run every 30th minute for every third hour for 1-22 hours

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

Is there any way to specify periods with cron without setting up multiple instances?

I want a cron job to run between 7 AM and 10 PM, every day, at 5 minute intervals. Normally this would be okay if it was 5 minute intervals, because you could just use "/5", but is there a way to specify it as 5 minute intervals but skip the times between 10PM and 7AM?
The minutes are specified separately from the hours in crontab. Specify minutes using the periodic notation, and the hours as a range.
*/5 7-21 * * * /path/to/script
Below would help for Quartz scheduler
0 00/5 7-21 * * ?

Run a cron job every minute only between 10 am to 5 pm

How do you run a cron job every minute only between office hours(10 am to 5pm)
I checked this thread Run a cron job every minute only on specific hours? but it doesn't answer my questions.
This should be correct:
* 10-16 * * 1-5 /path/to/my-script
So every single minute, between and including 10am and 5pm, every day in every month that is a day between and including monday to friday. Obviously "office hours" is a fuzzy expression, many people have other schedules ;-)
Unfortunately I fail to see an easy solution to get the script executed also exactly on 5pm...
* 10-16 * * * /path/to/executable/file argument_1 argument_2
Yes, you can define hours range.
Someone tried to edit my answer but as documentation says hours in range are inclusive http://team.macnn.com/drafts/crontab_defs.html so don't change 16 to 17.
It does,
Access your shell script and add the following
* 10-17 * * *
This means run every min, between these hours, on every day, of every month etc

Resources