Skip to content

Commit

Permalink
Drop deprecated periodic sync
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed May 9, 2024
1 parent afb4b86 commit de9850d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 57 deletions.
10 changes: 0 additions & 10 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ func shutdownEcho(e *echo.Echo) {
}
}

func shutdownEngine() {
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
if err := engine.ShutdownPeriodicSync(ctx); err != nil {
logrus.Errorf("unable to shutdown periodic sync: %v", err)
}
}

func shouldSkipAuth(path string) bool {
return strings.HasPrefix(path, "/plugin") || path == "/healthcheck" || path == "/metrics"
}
Expand Down Expand Up @@ -172,7 +164,6 @@ func StartAPI() error {
defer agent.Close()

setupEngine()
go engine.RunPeriodicSync()

e := setupEcho()
go handleSignals(func() {
Expand All @@ -181,7 +172,6 @@ func StartAPI() error {

err := e.Start(fmt.Sprintf(":%d", viper.GetInt("port")))
logrus.Infof("Shutting down server: %v", err)
shutdownEngine()
if err != nil && err != http.ErrServerClosed {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package api

import (
"github.com/google/gops/agent"
"github.com/tsuru/acl-api/engine"
)

func StartWorker() error {
Expand All @@ -16,7 +15,5 @@ func StartWorker() error {
defer agent.Close()

setupEngine()
go handleSignals(shutdownEngine)
engine.RunPeriodicSync()
return nil
}
44 changes: 0 additions & 44 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package engine

import (
"context"
"encoding/json"
"sync"
"time"
Expand Down Expand Up @@ -65,7 +64,6 @@ type EngineWithHooks interface {

var (
enabledEngines []func() Engine
quitCh = make(chan struct{})
)

func syncRule(log *logrus.Entry, ruleSvc rule.EngineRuleService, e Engine, r types.Rule, force bool) (err error) {
Expand Down Expand Up @@ -151,52 +149,10 @@ func engineSync(e Engine, rules []types.Rule, logicCache rule.LogicCache, force
}
}

func syncAllRules() error {
logrus.Info("Starting sync engines")
defer logrus.Info("Done sync engines")
ruleSvc := rule.GetServiceForEngine()
rules, err := ruleSvc.FindAll()
if err != nil {
return err
}
SyncRules(rules, false)
return nil
}

func EnableEngine(eng func() Engine) {
enabledEngines = append(enabledEngines, eng)
}

func ShutdownPeriodicSync(ctx context.Context) error {
select {
case quitCh <- struct{}{}:
return nil
case <-ctx.Done():
return ctx.Err()
}
}

func RunPeriodicSync() {
logrus.Info("Starting sync loop")
if viper.GetBool("sync.disabled") {
return
}

for {
syncInterval := viper.GetDuration("sync.interval")
err := syncAllRules()
if err != nil {
logrus.Errorf("error trying to run sync engines: %v", err)
}
select {
case <-time.After(syncInterval):
case <-quitCh:
logrus.Info("Stopping sync loop")
return
}
}
}

func SyncRules(rules []types.Rule, force bool) {
logicCache := rule.NewLogicCache()
wg := sync.WaitGroup{}
Expand Down

0 comments on commit de9850d

Please sign in to comment.