Spring Scheduled job with cron, only for the next 3 days - cron

I am trying to run a method every 10 minutes for the next 3 days and only that.
I have tried this :
cron.expression=0 */10 * * * ?
This will run every 10 minutes every day, every month.
But I only want it to be limited to the next 3 days starting from NOW.
I just can't find how to use (now -> 3 days) in cron
I am using this website and Spring scheduler Spring scheduler doc without success

Based on the Spring specs you can't define this logic directly in to the cron record. You should add such logic in to the program you run with this cron

Related

How to execute a cron expression for every 2.5 min

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?

hybris make cronjob execute over n hours, then n+1 hours

How do I achieve this? I mean, I can make it execute every n hours using triggers. But how do I make it execute every n hours, then every n + 1 hours, then repeat this loop?
You can change trigger of cron job with updating job trigger item (Trigger).
You can create a single trigger for this. For example "5 3-6/1 * * *" which stands for "At minute 5 past every hour from 3 AM through 6 AM."
After your business logic is done receive the trigger of the cron job set a new activation time and store it via model service.
This will re-schedule the cronjob out-of-the-box.
In you case it could be helping to configure the trigger at a fixed date in the past so the automatic re-scheduling do not happen.

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

Cron job time syntax

I have a cron job that processes an action for several records in my database. I want it to process each record with a 5 minute delay, then repeat the process every 12 hours. What is the syntax that I need to use to make this happen? For example, if I have 5 rows in my database that the cron job will process. I want it to process the first row, then process the next row 5 minutes later, then process the next row 5 minutes later, etc. until all rows have been processed. Then repeat the whole process every 12 hours. I tried using */5 */12 * * * but it did not work.
It won't work the way you have configured.
if I have 5 rows in my database that the cron job will process. I want it to process the first row, then process the next row 5 minutes later, then process the next row 5 minutes later, etc
Write a shell scrip to achieve above goal. Cron won't do it for you. Hint: use sleep function in your scrip to wait for 5 minutes before processing next record.
Then repeat the whole process every 12 hours
use * */12 * * * in cron to let your shell script run after every 12 hrs.
So, in short, Cron will trigger a run of you script very 12 hrs AND your script has the logic to wait for 5 minutes between processing any two consecutive DB records.

Azure WebRole Scheduled Task Every Morning

I am trying to figure out a solution to getting a WebRole to run a Task every morning at 5AM. I have looked at Quartz.Net and the examples on stackoverflow but all of them schedule the task to run every 10 minutes. Are there any examples that show how I can schedule it?
You might also want to check out the Scheduler add-on in the Windows Azure Store (login to the portal at manage.windowsazure.com, head to Add-Ons, then hit App Services and select Scheduler).
Up to 5,000 scheduled jobs/month are free.
Quartz.Net should be good for you.Try to use CronTrigger (or CronTriggerImpl in version 2.x).
Example of cron-expression - "0 0 5 * * ?" - run every day at 5 AM.
Cron trigger sub-expression position meaning:
Seconds - 0 for you (run at 0 second)
Minutes - 0 for you (run at 0 minutes)
Hours - 5 for you (run at 5 hour; it uses 24-hour clock)
Day-of-Month - * - run every day
Month - * for you (run every month)
Day-of-Week - ? - not specified for you (Day-of-Month has been used instead)
Year (optional field) - not used

Resources