diff --git a/.gitignore b/.gitignore index b6ef7c2..05bd204 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ example.json *.env *.out vendor -api.http diff --git a/api.http b/api.http new file mode 100644 index 0000000..59b93ef --- /dev/null +++ b/api.http @@ -0,0 +1,6 @@ +POST http://localhost:8000/api/v1/eval/jamie-menu-64623317-d00c-4508-8db3-613d1ed24638/ +Content-Type: application/json + +{ + "idade":13 +} \ No newline at end of file diff --git a/config/config.go b/config/config.go index 8e3fe4a..4088ec5 100644 --- a/config/config.go +++ b/config/config.go @@ -79,6 +79,7 @@ func LoadConfig() (err error) { if err2, ok := err.(*os.PathError); !ok { err = err2 log.Errorf("Error on Load Config: %v", err) + return } } @@ -102,7 +103,6 @@ func LoadConfig() (err error) { config.ResolverBridgeHeaders.Set(entries[0], entries[1]) } } - return } diff --git a/services/rulles.go b/services/rulles.go index 568a4e5..45bcfb1 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -175,13 +175,22 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K existing := s.knowledgeBaseCache[info] if existing == nil { - + var ExpirationDate time.Time + + switch s.expirationType { + case "seconds": + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second) + case "minutes": + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute) + case "hours": + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) + } existing = &knowledgeBaseCache{ KnowledgeBase: s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version), - ExpirationDate: time.Now().Add(time.Minute * 5), + ExpirationDate: ExpirationDate, } s.knowledgeBaseCache[info] = existing - + return existing.KnowledgeBase, nil } if existing.KnowledgeBase.Version != "latest" && len(existing.KnowledgeBase.RuleEntries) > 0 { return existing.KnowledgeBase, nil @@ -192,7 +201,12 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K } loadMutex.Lock() - s.knowledgeLibrary.RemoveRuleEntry(existing.KnowledgeBase.Name, knowledgeBaseName, version) + + for key := range existing.KnowledgeBase.RuleEntries { + + s.knowledgeLibrary.RemoveRuleEntry(key, knowledgeBaseName, version) + } + err := s.LoadRemoteGRL(knowledgeBaseName, version) if err != nil { log.Errorf("Erro on load: %v", err)