hyperjumptech/grule-rule-engine

Is it safe to delete rules on the running production engine ?

ArchyLi1996 opened this issue · 0 comments

Describe the bug

i use RemoveRuleEntry on the running production engine ,

kb := mylib.GetKnowledgeBase("MyKnowledge", "0.0.1")
	kb.RemoveRuleEntry("ruleName")
  1. GetSnapshot return nil pointer error

To Reproduce
Steps to reproduce the behavior:
Multiple runs

func main() {
      // funcBuildKB use BuildRuleFromResource to load rules 
      funcBuildKB()
      go forEach()
      time.Sleep(1 * time.Second)
      // funcDelte use RemoveRuleEntry to delte rules
      funcDelte()
      time.Sleep(100000 * time.Second)

}
func forEach() {
	for i := 0; i < 10000; i++ {
		version := "0.0.1"
		func1(version)
	}
}

func func1(version string) {
	knowledgeBase, errS := KnowledgeLibrary.NewKnowledgeBaseInstanceV2("TutorialRules", version)
	if errS != nil {
		// panic(errS)
	}
	myFact := &MyFact{
		IntAttribute:     123,
		StringAttribute:  "Some string value",
		BooleanAttribute: true,
		FloatAttribute:   1.234,
		TimeAttribute:    time.Now(),
	}
	dataCtx := ast.NewDataContext()
	err := dataCtx.Add("F", myFact)
	if err != nil {
		panic(err)
	}
	engineTmp := engine.NewGruleEngine()
	err = engineTmp.Execute(dataCtx, knowledgeBase)
	if err != nil {
		panic(err)
	}
}

Expected behavior

  1. I hope this error will not be thrown out
    image

  2. NewKnowledgeBaseInstance not use AstLog.Fatalf, It is better to use error to return

image