Skip to content

Commit

Permalink
fix: change worker config to map
Browse files Browse the repository at this point in the history
  • Loading branch information
Femi Novia Lina committed Aug 23, 2024
1 parent 3fcd8c4 commit 4d6591a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
13 changes: 6 additions & 7 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ type Config struct {
}

type SyncerConf struct {
SyncInterval time.Duration `mapstructure:"sync_interval" default:"1s"`
RefreshInterval time.Duration `mapstructure:"refresh_interval" default:"3s"`
ExtendLockBy time.Duration `mapstructure:"extend_lock_by" default:"5s"`
SyncBackoffInterval time.Duration `mapstructure:"sync_backoff_interval" default:"5s"`
MaxRetries int `mapstructure:"max_retries" default:"5"`
Workers []WorkerConfig `mapstructure:"workers"`
SyncInterval time.Duration `mapstructure:"sync_interval" default:"1s"`
RefreshInterval time.Duration `mapstructure:"refresh_interval" default:"3s"`
ExtendLockBy time.Duration `mapstructure:"extend_lock_by" default:"5s"`
SyncBackoffInterval time.Duration `mapstructure:"sync_backoff_interval" default:"5s"`
MaxRetries int `mapstructure:"max_retries" default:"5"`
Workers map[string]WorkerConfig `mapstructure:"workers" default:"[]"`
}

type WorkerConfig struct {
Name string `mapstructure:"name"`
Count int `mapstructure:"count" default:"1"`
Scope map[string][]string `mapstructure:"labels"`
}
Expand Down
2 changes: 1 addition & 1 deletion cli/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartWorkers(ctx context.Context, cfg Config) error {
return nil
}

func spawnWorkers(ctx context.Context, resourceService *core.Service, workerModules []WorkerConfig, syncInterval time.Duration, eg *errgroup.Group) {
func spawnWorkers(ctx context.Context, resourceService *core.Service, workerModules map[string]WorkerConfig, syncInterval time.Duration, eg *errgroup.Group) {
if len(workerModules) == 0 {
resourceService.RunSyncer(ctx, 1, syncInterval, map[string][]string{}, eg)
} else {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e_test/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ func (s *WorkerTestSuite) TestWorkerDefault() {
func (s *WorkerTestSuite) TestWorkerScope() {
projectScope := []string{s.resources[0].Project}
workerConfig := cli.WorkerConfig{
Name: "test-project-0-worker",
Count: 1,
Scope: map[string][]string{
"project": projectScope,
},
}

s.appConfig.Syncer.Workers = []cli.WorkerConfig{workerConfig}
s.appConfig.Syncer.Workers = map[string]cli.WorkerConfig{"test-project-0-worker": workerConfig}
testbench.SetupWorker(s.T(), s.ctx, *s.appConfig)

s.Run("running worker with project scoped config will run worker(s) that takes configured project job", func() {
Expand Down

0 comments on commit 4d6591a

Please sign in to comment.