Skip to content

Commit

Permalink
add some params data to context and fix lock job parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Jul 31, 2022
1 parent a5d2a2b commit e571bc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/job/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"context"
"flag"
"math/rand"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -196,6 +197,10 @@ func (r *Runner) runJobs(ctx context.Context, cfg *config.MultiConfig, metric *m
}

ctx := context.WithValue(ctx, templates.ContextKey("config"), cfgMap)
ctx = context.WithValue(ctx, templates.ContextKey("global_config"), r.globalJobsCfg)
ctx = context.WithValue(ctx, templates.ContextKey("goos"), runtime.GOOS)
ctx = context.WithValue(ctx, templates.ContextKey("goarch"), runtime.GOARCH)
ctx = context.WithValue(ctx, templates.ContextKey("metrics"), metric)

for j := 0; j < cfg.Jobs[i].Count; j++ {
if cfg.Jobs[i].Name != "" {
Expand Down
4 changes: 2 additions & 2 deletions src/job/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ func lockJob(ctx context.Context, args config.Args, globalConfig *GlobalConfig,
Job config.Config
}

if err := mapstructure.Decode(templates.ParseAndExecuteMapStruct(logger, args, ctx), &jobConfig); err != nil {
if err := ParseConfig(&jobConfig, args, *globalConfig); err != nil {
return nil, fmt.Errorf("error parsing job config: %w", err)
}

unlock := locker.Lock(jobConfig.Key)
unlock := locker.Lock(templates.ParseAndExecute(logger, jobConfig.Key, ctx))
defer unlock()

job := Get(jobConfig.Job.Type)
Expand Down

0 comments on commit e571bc9

Please sign in to comment.