Skip to content

Caching issue with engine #280

@iprasla

Description

@iprasla

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions