gpadbidri commented on issue #6318:
URL:
https://github.com/apache/incubator-kie-drools/issues/6318#issuecomment-2823751312
@tkobayas Yes application dynamically updates rules and this same rule is
created every time for each user and we have good traffic on our site. Her is
my code sample and generated drl which works in some cases and fails in some
cases :
`
public static boolean evaluateRules(List<RuleSnapshot> ruleList,
ContactMessage contactMessage, String parentId, String childId) {
var email = contactMessage.getEmail();
KieSession session = null;
try {
Map<String, Object> references =
ConditionUtils.references(ruleList);
String drl = ConditionUtils.getDrlString(ruleList, references);
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write("src/main/resources/simple.drl",
kieServices.getResources().newReaderResource(new
StringReader(drl)));
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
KieModule kieModule = kieBuilder.getKieModule();
session =
kieServices.newKieContainer(kieModule.getReleaseId()).newKieSession();
var result = new RuleResult();
session.setGlobal("result", result);
if (Objects.nonNull(references)) {
for (Map.Entry<String, Object> entry :
references.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
session.setGlobal(key, value);
}
session.insert(contactMessage);
session.fireAllRules();
var ruleResult = result.isValid();
return ruleResult;
} catch (Exception e) {
log.info("Exception in check rule : " + e.getMessage() + "
email = " + email );
e.printStackTrace();
return false;
} finally {
if (session != null) {
session.dispose(); // Always dispose session to prevent
memory leaks
log.info("[Thread: {}] KieSession disposed",
Thread.currentThread().getName());
}
}
}`
This is the generated drl which runs for few contacts and fails for few :
`package com.project.model.processing.contact;
global com.project.model.processing.contact.ContactEvent ref1;
global com.project.dto.compositetypes.rules.RuleResult result;
dialect "mvel"
rule "Match contact to fit Condition"
when
contactMessageInstance:ContactMessage( ( contactEvents contains ref1
) );
then
result.setValid(true);
end`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]