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.
Related
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
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
I wonder if it is possible to write an cron expression with several conditions:
Job should be run with given interval in minutes. For example with interval 42 minutes the fire times would be 10:00, 10:42, 11:24, 12:06 and etc.
If the current minute does not end with 0 (e.g. 10:28,10:29), then cron first fire time should be 10:30. So it means that first fire time should have "round" minutes.
I hope that you understand these conditions. Is it possible to describe them with quartz cron?
You can use job trigger like described below in Quartz.net 3.0:
var jobTrigger = TriggerBuilder.Create()
.StartNow()
.WithSimpleSchedule(s => s
.WithIntervalInMinutes(42)
.RepeatForever())
.Build();
And you can restart app at first round time, so it will fire first time at the same time only.
I usually use http://www.cronmaker.com/ to generate my cron expressions. And if you try the every 42 mins option you'll get the following expression: " 0 0/42 * 1/1 * ? *". As for the "round" minutes thing, you can try this when building your trigger:
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity(JobTrigger, JobGroup)
.WithCronSchedule(CroneExpression)
.StartAt(new DateTimeOffset(DateTime.Now,
TimeSpan.FromMinutes(DateTime.Now.Minute % 10)))
.Build();
It is not possible, see for explanation and similar issue: Quartz.net - Repeat on day n, of every m months?
it is also not possible by Cron expressions. To do this, you would need to apply some complex logic, use some operator that is not present in evaluators. Why do you need this? Would you like to combine those 2 requirements and create single complex pattern?
How should I go about creating a cron expression that will fire every 90 minutes continuously after midnight?
Documentation here:
http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
Pratik
I would just configure two cron jobs:
#min hr everything else
0 0,3,6,9,12,15,18,21 ...
30 1,4,7,10,13,16,19,22 ...
(you could also use the short form for the hours as well, like 0-21/3 and 1-22/3).
Don't use CronTrigger for such a schedule. Use one of the other trigger types such as SimpleTrigger or CalendarIntervalTrigger etc.
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.