Search code examples
drools

Drools: timer vs. duration attributes


Drools' documentation says that timer attribute is preferred now over duration:

Rules now support both interval and cron based timers, which replace the now deprecated duration attribute.

But I've detected that such rule wouldn't work:

rule "Expired auth"
    timer(int: 5s)

    when
        $auth   : Authorized()
        $noauth : NotAuthorized()
    then
        retract($auth);
        retract($noauth);
end

because when it gets evaluated a first time all the facts are being removed and the rule won't be scheduled as expected. But I've found that a rule with duration attribute works as it should:

rule "Expired auth"
    duration(5s)

    ...
end

So is there any way to do it via timers?


Solution

  • duration is mapped to an interval timer, so they work the same. Your issue is probably else where.

    See line 176 https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java#L176