Skip to content

Commit

Permalink
feat: modular worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Femi Novia Lina committed Aug 13, 2024
1 parent 5367819 commit e08df35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cli/serve.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"sync"
"time"

"github.com/newrelic/go-agent/v3/newrelic"
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 7 additions & 1 deletion cli/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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",
Expand All @@ -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)
Expand Down

0 comments on commit e08df35

Please sign in to comment.