can not remove rule
See original GitHub issueHello,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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
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 directlypriotizedRules
object if thepriotizedRules
list is not empty. Despite removeRule() does not clear thepriotizedRules
list. So even if you callremoveRule()
,run
method is first looking topriotizedRules
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.