Skip to content

Commit

Permalink
simplify backoff config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Mar 31, 2022
1 parent 66a6203 commit 910895a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/job/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ type BasicJobConfig struct {
IntervalMs int `mapstructure:"interval_ms,omitempty"`
Interval *time.Duration `mapstructure:"interval"`
utils.Counter
*utils.BackoffConfig
Backoff *utils.BackoffConfig
}

func (c *BasicJobConfig) FromGlobal(global GlobalConfig) {
if c.GetInterval() < global.MinInterval {
c.Interval = &global.MinInterval
}

if c.BackoffConfig == nil {
c.BackoffConfig = &global.Backoff
if c.Backoff == nil {
c.Backoff = &global.Backoff
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/job/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func fastHTTPJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalCo
return nil, err
}

backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.BackoffConfig, globalConfig.Backoff))
backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.Backoff, globalConfig.Backoff))

client := http.NewClient(ctx, *clientConfig, logger)

Expand Down
2 changes: 1 addition & 1 deletion src/job/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func packetgenJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalC
return nil, fmt.Errorf("error parsing job config: %w", err)
}

backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.BackoffConfig, globalConfig.Backoff))
backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.Backoff, globalConfig.Backoff))

trafficMonitor := metrics.Default.NewWriter(metrics.Traffic, uuid.New().String())
go trafficMonitor.Update(ctx, time.Second)
Expand Down
2 changes: 1 addition & 1 deletion src/job/rawnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func tcpJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig,
return nil, err
}

backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.BackoffConfig, globalConfig.Backoff))
backoffController := utils.NewBackoffController(utils.NonNilBackoffConfigOrDefault(jobConfig.Backoff, globalConfig.Backoff))

if globalConfig.ProxyURLs != "" {
jobConfig.proxyURLs = templates.ParseAndExecute(logger, globalConfig.ProxyURLs, ctx)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func Sleep(ctx context.Context, t time.Duration) bool {
}

type BackoffConfig struct {
Multiplier int `mapstructure:"backoff_multiplier"`
Limit int `mapstructure:"backoff_limit"`
Timeout time.Duration `mapstructure:"backoff_timeout"`
Multiplier int
Limit int
Timeout time.Duration
}

func DefaultBackoffConfig() BackoffConfig {
Expand Down

0 comments on commit 910895a

Please sign in to comment.