From e08df351781800daf0c211a99178494e9bdfa24b Mon Sep 17 00:00:00 2001 From: Femi Novia Lina Date: Tue, 13 Aug 2024 15:41:20 +0700 Subject: [PATCH] feat: modular worker --- cli/serve.go | 8 +++++++- cli/worker.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cli/serve.go b/cli/serve.go index c6ecda06..3d1f6973 100644 --- a/cli/serve.go +++ b/cli/serve.go @@ -1,6 +1,7 @@ package cli import ( + "sync" "time" "github.com/newrelic/go-agent/v3/newrelic" @@ -60,8 +61,13 @@ func cmdServe() *cobra.Command { } } + var wg *sync.WaitGroup if spawnWorker { - go spawnWorkers(cmd.Context(), resourceService, cfg.Syncer.WorkerModules, cfg.Syncer.SyncInterval) + go func() { + wg = spawnWorkers(cmd.Context(), resourceService, cfg.Syncer.WorkerModules, cfg.Syncer.SyncInterval) + wg.Wait() + zap.L().Info("all syncer workers exited") + }() } return entropyserver.Serve(cmd.Context(), diff --git a/cli/worker.go b/cli/worker.go index fd6c3e77..2c77ed3c 100644 --- a/cli/worker.go +++ b/cli/worker.go @@ -11,6 +11,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/goto/entropy/core" "github.com/goto/entropy/core/module" + "github.com/goto/entropy/pkg/logger" "github.com/spf13/cobra" "go.uber.org/zap" ) @@ -20,7 +21,7 @@ func cmdWorker() *cobra.Command { Use: "worker", Short: "Start workers", Example: heredoc.Doc(` - $ entropy worker + $ entropy worker --count 2 --scope project=example-project,example-project-2 `), Annotations: map[string]string{ "group:other": "server", @@ -33,6 +34,11 @@ func cmdWorker() *cobra.Command { return err } + err = logger.Setup(&cfg.Log) + if err != nil { + return err + } + store := setupStorage(cfg.PGConnStr, cfg.Syncer, cfg.Service) moduleService := module.NewService(setupRegistry(), store) resourceService := core.New(store, moduleService, time.Now, cfg.Syncer.SyncBackoffInterval, cfg.Syncer.MaxRetries)