question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can not remove rule

See original GitHub issue

Hello,I’m looking for a rule engine written in js,and I find this project easy to use,and following is my problem using the engine. I add a rule,then run the engine per 1 second. After 3 seconds,I remove the rule. However,I still got “hello-world!” per second. I think there need to be a remove rule test. I have a look at the source code,the problem can be solved by adding this.prioritizedRules = null to removeRule.

Here is my code



let Engine = require('json-rules-engine').Engine
let Rule = require('json-rules-engine').Rule

let engine = new Engine()
let rule = new Rule({
  conditions: {
    all: [{
      fact: 'displayMessage',
      operator: 'equal',
      value: true
    }]
  },
  event: {
    type: 'message',
    params: {
      data: 'hello-world!'
    }
  }
})
engine.addRule(rule)
engine.addFact('displayMessage', true);
engine.on('success', (event, almanac, ruleResult) => {
  console.log(event.params.data)
})
setInterval(() => {
  engine
    .run()
}, 1000);
setTimeout(() => {
  console.log('remove');
  engine.removeRule(rule);
}, 3000)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CacheControlcommented, Apr 11, 2019

@ozanerturk thanks for checking into this, and the offer to implement a fix.

I agree with your assessment. I think a good fix would be to add a line for setting the prioritizedRules variable to null, similar to how addRule() does it:

https://github.com/CacheControl/json-rules-engine/blob/5ac00eafdf84eb93def58a44008e96bf7bd81bf4/src/engine.js#L56

1reaction
ozanerturkcommented, Apr 9, 2019

I checked the scenario @hehejiuhuizhe seems rigth. I came across with same result. when I debugged the code I realize run method calls prioritizeRules() and it returns directly priotizedRules object if the priotizedRules list is not empty. Despite removeRule() does not clear the priotizedRules list. So even if you call removeRule() , run method is first looking to priotizedRules list to do the job and because removeRule does not clear the list there is still available rule in priotizedRules list.

https://github.com/CacheControl/json-rules-engine/blob/5ac00eafdf84eb93def58a44008e96bf7bd81bf4/src/engine.js#L146

https://github.com/CacheControl/json-rules-engine/blob/5ac00eafdf84eb93def58a44008e96bf7bd81bf4/src/engine.js#L64

Simply little cache mechanizm brokes it. The list has to be recreated after removeRule method called or force to create new one in prioritizeRules method. @CacheControl if you think this is the reason I can implement the fix if we agree on an idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Outlook 365 rule error "Cannot remove message from the folder"
Outlook 365 rule error "Cannot remove message from the folder" · 1. Recreate new archive .pst · 2. run Outlook.exe /clean rules, then...
Read more >
Firewall config error: Cannot delete rule set (still in use)
Go to the security tab. On the right, under the rule-set you want to remove, click on action, then select interfaces. This will...
Read more >
rule can not be removed - Atlassian Community
yes, i mean automation rules. I can create them, but after they are created, it's not possible to further configure or delete them....
Read more >
Troubleshoot issues deleting an Amazon VPC security group
If the security group is referenced in one of its own rules, then you must remove the rule before deleting the security group....
Read more >
NSG rule delete shouldn't be prevented by a delete lock #16958
Note that rules can be successfully deleted from Load Balancers and App Gateways in the same resource group (with the delete lock).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found