javadroolskieredhat-brms

Agenda groups not working as expected in Drools


Right now, in my drools project I have two groups of rules in separate DRL files which are split by agenda groups. For the agenda group "preCheck" I am setting auto focus to true for each rule in that agenda group. Example:

rule "preCheckDuplicate"
    agenda-group "preCheck"
    auto-focus true
    no-loop true
    salience 50
    when
        $f : IngestFileMetadata(isDuplicate.equalsIgnoreCase("True"))
    then
        $f.setIsDuplicate("True");
end

For the other agenda group - "defaultRules" - the rules do NOT have the auto focus attribute set. Example:

rule "duplicate file default"
    agenda-group "defaultRules"
    activation-group "isDuplicate"
    no-loop true
    salience 0
    when
        $f : IngestFileMetadata(isDuplicate.equals("True"))
    then
        insert(createResponse($f));
end

When invoking the rules via the rest API, I am also trying to set focus to the "preCheck" agenda group through the JSON payload. Example:

{
  "lookup": "defaultStatelessKieSession",
  "set-focus": "preCheck",
  "commands": [
    {
      "insert": {
        "out-identifier": "IngestFileMetadata",
        "return-object": "true",
        "entry-point": "DEFAULT",
        "object": {
          "com.hms.ingestion.rules.IngestFileMetadata": {
              * * * * * data attributes here * * * * *
          }
        }
      }
    },
    {
      "fire-all-rules": {"out-identifier": "fired"}
    },
    {
      "query": {"name": "rulesResponses", "out-identifier": "rulesResponses"}
    }
  ]
}

However, when the rules are executed, it seems like the rules in the "defaultRules" agenda group are being evaluated first. I have no idea why. I'm relatively new to drools so it's entirely possible I'm not correctly understanding the concept of agenda groups, but I was sure this design would ensure the "preCheck" rules would evaluate first.

Can anyone provide any insight on why this is not happening? If I need to provide more details I can.

Thanks in advance.


Solution

  • Turns out my issue was having to issue an explicit update to my fact once I updated the attributes during my pre-check rule. That solved the problem.