From f09272d4a334360f4eb240541b67b36f3a27c6d3 Mon Sep 17 00:00:00 2001 From: "Joel D. Elkins" Date: Sat, 13 Aug 2022 23:10:33 -0500 Subject: [PATCH] Misc cleanup --- cmd/execute.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/execute.go b/cmd/execute.go index 2e85b84..483729b 100644 --- a/cmd/execute.go +++ b/cmd/execute.go @@ -23,6 +23,7 @@ package cmd import ( "fmt" + "strconv" "sync" "time" @@ -33,17 +34,12 @@ import ( "golang.org/x/exp/slices" ) -type runner struct{ - GetSet func(*container.Container) command.CommandSet - GroupScale int -} - func execForEach(tgts []container.Container, getSet func(*container.Container) command.CommandSet, groupScale int) { var ser sync.Mutex // serialize non-async containers runLevel := make(map[int][]container.Container) for i := range tgts { - rl := int(tgts[i].StartGroup * groupScale) + rl := tgts[i].StartGroup * groupScale runLevel[rl] = append(runLevel[rl], tgts[i]) } @@ -53,7 +49,13 @@ func execForEach(tgts []container.Container, getSet func(*container.Container) c for _, r := range rls { cs := runLevel[r] ser.Lock() - fmt.Fprintln(output, "*** Running a command set for group", r, mapNames(cs)) + var dispScale string + if groupScale == 0 { + dispScale = "" + } else { + dispScale = strconv.Itoa(r / groupScale) + } + fmt.Fprintln(output, "*** Running a command set for group", dispScale, mapNames(cs)) go func(async bool, conts []container.Container, ser *sync.Mutex) { var wg sync.WaitGroup defer func() { @@ -78,9 +80,9 @@ func runSet(cont *container.Container, getSet func(*container.Container) command for _, cmd := range set.Commands { if err := cmd.Execute(output, fake, set.ID); err != nil { cont.LogEntry().WithFields(log.Fields{ - "error": err, + "error": err, "action": set.ID, - }).Errorln("Failed") + }).Errorln("Failed") return } } @@ -94,4 +96,3 @@ func mapNames(conts []container.Container) string { } return fmt.Sprintf("%v", names) } -