Skip to content

Commit

Permalink
Merge pull request #32 from k1LoW/countup-before-execute
Browse files Browse the repository at this point in the history
Fix counting the number of executions
  • Loading branch information
k1LoW authored Nov 22, 2019
2 parents ebd4855 + 9da34f7 commit f0bcd25
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var trackCmd = &cobra.Command{
fields = append(fields, zap.Any(o.key, o.value))
}
exceeded := 0
executed := 0
execution := 0
l.Info(startMessage, fields...)
sg := sync.WaitGroup{}

Expand Down Expand Up @@ -194,9 +194,14 @@ var trackCmd = &cobra.Command{
} else {
exceeded = 0
}
if times > 0 && execution >= times {
break L
}
if exceeded >= attempts {
sg.Add(1)
go func(ctx context.Context) {
execution++
exceeded = 0
fields := []zap.Field{}
m.Each(func(metric metrics.Metric, value interface{}) {
fields = append(fields, zap.Any(metric.Name, value))
Expand All @@ -216,14 +221,9 @@ var trackCmd = &cobra.Command{
} else {
l.Info(noExecuteMessage, fields...)
}
executed++
exceeded = 0
sg.Done()
}(ctx)
}
if times > 0 && executed >= times {
break L
}
case <-ctx.Done():
break L
}
Expand Down

0 comments on commit f0bcd25

Please sign in to comment.