diff --git a/api/api.go b/api/api.go index 095ef1f..45a52a6 100644 --- a/api/api.go +++ b/api/api.go @@ -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" } @@ -172,7 +164,6 @@ func StartAPI() error { defer agent.Close() setupEngine() - go engine.RunPeriodicSync() e := setupEcho() go handleSignals(func() { @@ -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 } diff --git a/api/worker.go b/api/worker.go index c700c07..ac03fec 100644 --- a/api/worker.go +++ b/api/worker.go @@ -6,7 +6,6 @@ package api import ( "github.com/google/gops/agent" - "github.com/tsuru/acl-api/engine" ) func StartWorker() error { @@ -16,7 +15,5 @@ func StartWorker() error { defer agent.Close() setupEngine() - go handleSignals(shutdownEngine) - engine.RunPeriodicSync() return nil } diff --git a/engine/engine.go b/engine/engine.go index 35b91bb..34ed071 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -5,7 +5,6 @@ package engine import ( - "context" "encoding/json" "sync" "time" @@ -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) { @@ -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{}