The Drools documentation mentions that rules can use attributes such as date-effectiveand date-expiresto indicate the validity period of an absolute rule.
for instance
rule "Date-restricted rule"
date-effective "20.2.2013 8:00"
date-expires "20.2.2013 16:00"
when
then
end
Drools also supports periodically repeating rules at intervals timer(int:)and cron like timer(cron:), but this means that the rule runs at such points.
Question:
I am wondering if there is any option how to specify periodically available (non-working) rules with a time limit. For example, let the image of working time in any company - the operation can be performed only during the official working period, but not after several hours.
I would like something like this, but this is not the right Drools rule
rule "Time-restricted rule"
time-effective "8:00"
time-expires "16:00"
when
then
end
8:00 16:00?
( ):
Drools , , , Quartz. StatefulSession WorkingMemory, StatelessSession, , , .
:
rule "Business hours only"
calendars "business-hours"
when
SomeAttachedClass()
then
System.out.println("Rule is fired");
end
import org.quartz.impl.calendar.DailyCalendar;
StatefulKnowledgeSession memory = session.newWorkingMemory();
DailyCalendar businessHours = new DailyCalendar( 8, 0, 0, 0, 16, 0, 0, 0 );
businessHours.setInvertTimeRange( true );
org.drools.time.Calendar businessHoursCalendar = QuartzHelper.quartzCalendarAdapter( businessHours );
memory.getCalendars().set( "business-hours", businessHoursCalendar );