views:

96

answers:

3

Hi,

I am using Quartz .Net to schedule my jobs in my application. I was just wondering if a CRON expression for the following scenario can be built :

Everysecond between 2:15AM and 5:20AM

Could someone please throw some light on this?

Thanks, Ram

+1  A: 

Regarding cron seconds support, there appears to be some difference in the syntax used between the UNIX cron tool and CRON Expression Wikipedia articles. According to the Quartz CRON Documentation however, seconds is supported.

Given the above, I would create three CRON Triggers to handle:

  1. 2:15:00 - 2:59:59
  2. 3:00:00 - 4:59:59
  3. 5:00:00 - 5:19:59

Which would translate to (I believe):

  1. * 15/1 2 * * ?
  2. * * 3-5 * * ?
  3. * 0-20 5 * * ?
robyaw
That would be every minute from 15-59 hour on the second of all months :p, seconds are normally not supported. It should work if you shift your expression to the left.
gauteh
I hear what you're saying, but in the context of Quartz and Quartz.NET, the fields are, seconds, minutes, hours, day-of-month, month, day-of-week, and year (optional).
robyaw
A: 

robyaw,

Thanks a lot for your answer. And I apologize for such a delay in replying. I had actually been off for a while. Your solution indeed works. I had to create 3 CRON triggers for the time range that I had specified. You were right with the time ranges that you had mentioned. However, for the 3 CRON expressions that you had mentioned. I am afraid they might not work as intended. These expressions work for the time range : 2:15AM - 5:20AM - Everyday

1) * 15-59 2 * * ? - Every second from 2:15AM to 3:00AM, ie, 2:15:00AM to 2:59:59AM

2) * 0-59 3-4 * * ? - Every second from 3:00AM to 5:00AM, ie, 3:00:00AM to 4:59:59AM

3) * 0-19 5 * * ? - Every second from 5:00AM to 5:20AM, ie, 5:00:00AM to 5:19:59AM

@gauteh : Please note that Quartz .Net actually supports secondly trigger.

Hope this helps others who might need a solution to a similar problem.

Thanks,

Ram

Ram
+1  A: 

You have here a interval trigger (every second) that translates cleanly to SimpleTrigger. What you need with it is a restriction to only allow it to run in specific time range (2:15 - 5:20). This you can achieve by using a calendar, more precisely a DailyCalendar. You can set daily calendar to have this time range and set the InvertTimeRange to true to include the range instead of default of excluding the range.

Read more about the calendars in the tutorial and DailyCalendar API documentation.

Marko Lahma
Marko, thanks for pointing out in the direction of using a calendar. It was really helpful...
Ram