I am using Quartz-Scheduler for repetitive tasks but I am facing a trouble. In my server side my user wants to specify some date range like From 2013-09-27
with in 09:00 AM - 12:00 PM
to 2013-09-30
Explanation:
Run a job from 2013-09-27
to 2013-09-30
but only between 09:00 AM - 12:00 PM
I am facing trouble in writing a Cron expression for it, furthermore my user is non-technical so my user wants me to create Cron expression automatically from both time stamp values.
Please help me out. Let me know if there is another way.
I have seen many resources on Google but I still can't find nothing.
Links:
http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-05
Does cron expression in unix/linux allow specifying exact start and end dates
Update
I have written one but it's not working
|------------------------------------------------------------------|
| Seconds | Minutes | Hours | DayOfMonth | Month | DayOfWeek | Year|
| | | | | | | |
| 0 | 0 | 9-12 | 27-30 | 9 | ? | 2013|
|------------------------------------------------------------------|
trying to map 2013-09-27
to 2013-09-30
but only between 09:00 AM - 12:00 PM
Updated I have also tried it running with
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(NAME_TRIGGER_TASK_UPDATER, GROUP_TASK_TRIGGER)
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 19-22 10 ? *")).build();
but it doesn't give any error nor go into my execute method of my job
cronSchedule("0 0 9-12 ? * ?") throws invalid schedule exception.
The code below runs it without respecting the start and end date.
String startDateStr = "2013-09-27 00:00:00.0";
String endDateStr = "2013-09-31 00:00:00.0";
Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(startDateStr);
Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(endDateStr);
CronTrigger cronTrigger = newTrigger()
.withIdentity("trigger1", "testJob")
.startAt(startDate)
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 * * ?"))
.endAt(endDate)
.build();