-
Notifications
You must be signed in to change notification settings - Fork 503
Closed
Description
I am having a use case scenario where I have a very simple rule that is run against provided fact(s). When I run the engine, I notice that on success event gets called multiple times hence it create duplicates. The example is below:
const engine = new Engine();
const countryRule = {
conditions: {
all: [
{
all: [
{
fact: 'country',
operator: 'equal',
value: 'IN',
},
{
fact: 'continent',
operator: 'equal',
value: 'Asia',
},
{
fact: 'state',
operator: 'in',
value: ['KERALA', 'PUNJAB', 'GUJARAT'],
},
],
},
],
},
event: {
type: 'rule-event-india',
params: {
message: 'The rule satisfy for India',
},
},
priority: 75,
};
engine.on('success', (event, almanac) => {
matchedResults.push(event.params.message);
});
engine.on('failure', ......) ....
// feedFactsToEngine is called by an API method
const feedFactsToEngine = async (feeds) => {
engine.addRule(countryRule);
engine.addFact('finders', '', { cache: false });
await Promise.all(feeds.map(f => engine.run(f)));
return matchedResults;
};
Metadata
Metadata
Assignees
Labels
No labels