How to make a rule active for only a certain time interval within the day?

Hi all,

I found that you can initiate a rule at a certain time leveraging the syntax:

rule "name of the rule"
when Timer cron "0 30 8 ? * MON-FRI"
then
 ...
end

I would like to have something like:

rule "name of the rule"
when (Timer > cron "0 30 8 ? * MON-FRI") and (Timer < cron "0 30 10 ? * MON-FRI")
then
 ...
end

to run a rule only for a certain part of the day.

Any idea how this can be accomplished?

Thank you
Justus

you can have the hours you like to have the rule running listed with commas or with a dash like this:

rule "name of the rule"
when Time cron "0 30 8,9,10 ? * MON-FRI"
then
 ...
end

or the same:

rule "name of the rule"
when Time cron "0 30 8-10 ? * MON-FRI"
then
 ...
end

http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06.html

How often would you like the rule to be triggered between 8:30 and 10:30? This will trigger the rule every 5 minutes:

rule "name of the rule"
when
    Time cron "0 30/5 8 ? * MON-FRI" // 30/5 means every 5 minutes starting at 30 minutes after the hour
    or
    Time cron "0 0/5 9 ? * MON-FRI"
    or
    Time cron "0 0-30/5 10 ? * MON-FRI" // 0-30/5 means every 5 minutes during the interval of 0 to 30 minutes after the hour
then
 ...
end

@ Thomas: Sorry for the typo … of course I meant “Time” not “Timer”

@ Scott: Thanks for this guidance! For cron this is definitely the reasonable way :slight_smile: (… and I must admit that I would have not come up with that idea on my own). Hence “Thanks for sharing” !!!
I thought that there might be a more elegant way that I did not realize :wink:
I will try this - THANK YOU!

Hi folks,

I have a similar requirement and want to trigger a rule every 8 minutes between 16h (4 pm) and 23h (11 pm). Therefore I created the following cron statement:

rule "XYZ"
when
Time cron “0 */8 16-23 * * ?”
then

However, according to the logs the rule is also triggered after 23h which is not the intended behavior. Is 23 h inclusive, i.e., meaning until 23.59?

Best
Daniel

By giving the time interval from 16-23 it includes to run your rule also at 23:00, 23:08, 23:16, 23:32, 23:40, 23:48 and 23:56. if you don’t want to have the rule to be run after 23h you have to change your cron entry to “16-22”.

Maybe Design Pattern: Time Of Day is a good attempt too for a solution.

You could configure a specific time of day Zone for the timespan you want the rule to be active and set up the Cron to the Intervall you need during the timespan.