0

I'm trying to create a cron expression that will trigger a job according to the time I get, and every X minutes. both start/end time and the minutes intervals are parametrs I get from the user. for example:

start time: 09:15 end time: 19:35 minutes interval: 15

I want the job to start at 09:15 and to be triggred every 15 minutes, so the last job will actually be at 19:30 (because it can't be after 19:35). my problem is that I dont know how to include the minutes of the start/end time..

How is it possible to create this kind of expression?

Thank's In advance.

user590586
  • 2,960
  • 16
  • 63
  • 96

2 Answers2

0

I don't think that it is possible to meet your requirements in a single cron expression, as each time component (hours/minutes/seconds etc) is handled independently.

Perhaps the simplest approach would be to have a trigger for running every 15 minutes, and enable/disable this trigger at 09:15 and 19:35 (e.g. using additional triggers).

Alternatively you could have a trigger fire every 15 minutes, and procedural logic attached to this trigger which checks if the current time is between 09:15 and 19:35 before doing any work.

Jason
  • 11
  • 1
0

You don't need CRON, simple trigger will do. Check out Lesson 5: SimpleTrigger. This should work for your situation:

trigger = newTrigger()
    .startAt(nineFifteen)
    .endAt(nineteenThirtyFive)
    .withSchedule(simpleSchedule().withIntervalInMinutes(15))
    .forJob(someJob)
    .build();
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674