Misc cleanup

This commit is contained in:
Joel Elkins 2022-08-13 23:10:33 -05:00
parent 71f830887e
commit f09272d4a3
No known key found for this signature in database
GPG Key ID: 133589DC38921AE2

View File

@ -23,6 +23,7 @@ package cmd
import ( import (
"fmt" "fmt"
"strconv"
"sync" "sync"
"time" "time"
@ -33,17 +34,12 @@ import (
"golang.org/x/exp/slices" "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) { func execForEach(tgts []container.Container, getSet func(*container.Container) command.CommandSet, groupScale int) {
var ser sync.Mutex // serialize non-async containers var ser sync.Mutex // serialize non-async containers
runLevel := make(map[int][]container.Container) runLevel := make(map[int][]container.Container)
for i := range tgts { for i := range tgts {
rl := int(tgts[i].StartGroup * groupScale) rl := tgts[i].StartGroup * groupScale
runLevel[rl] = append(runLevel[rl], tgts[i]) 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 { for _, r := range rls {
cs := runLevel[r] cs := runLevel[r]
ser.Lock() ser.Lock()
fmt.Fprintln(output, "*** Running a command set for group", r, mapNames(cs)) var dispScale string
if groupScale == 0 {
dispScale = "<all>"
} 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) { go func(async bool, conts []container.Container, ser *sync.Mutex) {
var wg sync.WaitGroup var wg sync.WaitGroup
defer func() { defer func() {
@ -78,9 +80,9 @@ func runSet(cont *container.Container, getSet func(*container.Container) command
for _, cmd := range set.Commands { for _, cmd := range set.Commands {
if err := cmd.Execute(output, fake, set.ID); err != nil { if err := cmd.Execute(output, fake, set.ID); err != nil {
cont.LogEntry().WithFields(log.Fields{ cont.LogEntry().WithFields(log.Fields{
"error": err, "error": err,
"action": set.ID, "action": set.ID,
}).Errorln("Failed") }).Errorln("Failed")
return return
} }
} }
@ -94,4 +96,3 @@ func mapNames(conts []container.Container) string {
} }
return fmt.Sprintf("%v", names) return fmt.Sprintf("%v", names)
} }