I'd like a rule to fire when it's 8am OR the sun is up. How to go about this?
rule X
when
( "it's 8am" and ... and ...)
or
(Sun( up ) and ... and ...)
then
// do something
end
A timer acts like a prerequisite. So I guess it's not useful in this case.
An extra time fact would have to be updated every second, which would cause the rule to refire every second. I guess I could split the time fact into hour, minute, and second facts, but that wouldn't really solve the problem, but only make it occur less often.
Is such a rule possible/viable in Drools?
So this is what I do to have time as an extra trigger:
1) Create a separate rule based solely on a cron trigger, which inserts a time-fact at 8am.
2) Have the actual rule check for the cron-triggered time fact.
insertLogical inserts a fact into memory and removes it when it's no longer needed. This is the time fact:
You could have a rule that is constantly keeping track of the time. Then your rule can just check for that time to fire. I used milliseconds for simplicity sake, but I think you can see how it can be adapted to whatever you want. To solve your firing issue every second issue, adapt the Time class to use Calendar objects or something along those lines. Just initialize your knowledge session with a Time object.