Cron expression for time range

I use Quartz.Net to schedule my tasks in my application. I'm just wondering if a CRON expression can be expressed for the following scenario:

Every second between 2:15 and 5:20 in the morning

+4
source share
3 answers

robyaw

Thank you very much for your response. And I apologize for such a delay in the response. Actually, I didn’t work for a while. Your solution really works. I had to create three CRON triggers for the time range I specified. You were right with the time ranges you mentioned. However, for the 3 CRON expressions you mentioned. I am afraid that they may not work properly. These expressions work for the time range: 2:15 AM - 5:20 AM - Everyday

1) * 15-59 2 * * ? - every second from 2:15 to 3:00, i.e. from 2:15:00 to 2:59:59 AM

2) * 0-59 3-4 * * ? - every second from 3:00 to 5:00, i.e. from 3:00:00 to 4:59:59 AM

3) * 0-19 5 * * ? - every second from 5:00 to 5:20, i.e. from 5:00:00 to 5:19:59.

@gauteh: Note that Quartz.Net actually supports the second trigger.

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

+5
source

Regarding support for cron seconds, there seems to be some difference in the syntax used by the UNIX cron tool and the CRON Expression on Wikipedia. According to the Quartz CRON Documentation , however, seconds are supported.

Given the above, I would create three CRON triggers for processing:

  • 2:15:00 - 2:59:59
  • 3:00:00 - 4:59:59
  • 5:00:00 - 5:19:59

To translate to (I believe):

  • * 15/1 2 * * ?
  • * * 3-5 * * ?
  • * 0-20 5 * * ?
+4
source

You have an interval trigger here (every second) that translates purely to SimpleTrigger. What you need is a restriction that allows it to work only in a certain time range (2:15 - 5:20). This can be achieved using the calendar, or rather DailyCalendar. You can set a daily calendar for this time range and set the InvertTimeRange parameter to true to include the range instead of the default value to exclude the range.

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

+1
source

Source: https://habr.com/ru/post/1316174/


All Articles