Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Drools Fusion have a concept of "now"?

I'm trying to write a rule that delays firing until, at least, 15 minutes have passed since the last firing. However, the temporal operators in Drools Fusion only allow reasoning about two events in relation to each other and not one event in relation to the current time.

I would like something like this:

rule "some rule"
when
    not LastFiredEvent(this before[0m, 15m] NOW)
    …

I have resorted to writing a rule that fires every second and inserts a heartbeat event (also retracting the previous heartbeat), which I can use in other rules to serve as the current time.

I find this rather inelegant; am I missing something or does Drools Fusion really not have something for this?

NB. I am not looking for delayed firing of rules or rules that can only fire on multiples of 15 minutes; if nothing has happened in the last 17 minutes, the rule must fire immediately in response to a new event.

like image 226
Francisco Canedo Avatar asked Jan 14 '11 14:01

Francisco Canedo


1 Answers

Although the concept of "NOW" might seem simple at first, it is not, as it is ambiguous and depends on the different semantics it can take based on the running environment. Drools Fusion does have a concept of "NOW" when you run it in STREAM mode, but it is different from what you are asking above. The explanation is a bit long to be done here, so lets focus on your problem.

First, you say: "I'm trying to write a rule that delays firing..." and then your say: "I am not looking for delayed firing of rules...", so I am confused about what you need.

If you want to delay the rule you can use the timer attribute:

rule X
   timer( int: 15m )
...

If you want to fire a rule in case an event did or did not happen within an interval, you can use sliding windows. E.g.:

rule "Event did not happen in the last 15m"
when
   not( SomeEvent() over time:window(15m) )
...

Hope that helps. And BTW, try posting your questions to the Drools mailing list as it will be easier for you to get an answer. I only saw your post because a friend pinged me about it.

Cheers, Edson

like image 186
Edson Tirelli Avatar answered Sep 21 '22 02:09

Edson Tirelli