mirror of
https://gitea.elkins.co/Networking/ccl.git
synced 2025-03-09 20:51:39 -05:00
Execute: probable bikeshedding
This commit is contained in:
parent
e3aa4c2ad2
commit
4caabc0327
@ -35,12 +35,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
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
|
runLevel := make(map[int][]*container.Container)
|
||||||
runLevel := make(map[int][]container.Container)
|
|
||||||
|
|
||||||
for i := range tgts {
|
for i := range tgts {
|
||||||
rl := tgts[i].StartGroup * groupScale
|
rl := tgts[i].StartGroup * groupScale
|
||||||
runLevel[rl] = append(runLevel[rl], tgts[i])
|
runLevel[rl] = append(runLevel[rl], &tgts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
rls := maps.Keys(runLevel)
|
rls := maps.Keys(runLevel)
|
||||||
@ -48,7 +47,6 @@ 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()
|
|
||||||
var dispScale string
|
var dispScale string
|
||||||
if groupScale == 0 {
|
if groupScale == 0 {
|
||||||
dispScale = "<all>"
|
dispScale = "<all>"
|
||||||
@ -56,27 +54,12 @@ func execForEach(tgts []container.Container, getSet func(*container.Container) c
|
|||||||
dispScale = strconv.Itoa(r / groupScale)
|
dispScale = strconv.Itoa(r / groupScale)
|
||||||
}
|
}
|
||||||
fmt.Fprintln(output, "*** Running a command set for group", dispScale, mapNames(cs))
|
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() {
|
|
||||||
wg.Wait()
|
|
||||||
ser.Unlock()
|
|
||||||
}()
|
|
||||||
for i := range conts {
|
|
||||||
wg.Add(1)
|
|
||||||
go runSet(&conts[i], getSet, &wg)
|
|
||||||
}
|
|
||||||
if !async {
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
}
|
|
||||||
}(r == 0, cs, &ser)
|
|
||||||
}
|
|
||||||
ser.Lock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func runSet(cont *container.Container, getSet func(*container.Container) command.CommandSet, wg *sync.WaitGroup) {
|
wg := new(sync.WaitGroup)
|
||||||
|
for i := range cs {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(cont *container.Container, set command.CommandSet) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
set := getSet(cont)
|
|
||||||
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{
|
||||||
@ -86,10 +69,17 @@ func runSet(cont *container.Container, getSet func(*container.Container) command
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}(cs[i], getSet(cs[i]))
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
if r != 0 {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For debugging
|
// For debugging
|
||||||
func mapNames(conts []container.Container) string {
|
func mapNames(conts []*container.Container) string {
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for i := range conts {
|
for i := range conts {
|
||||||
names = append(names, conts[i].Name)
|
names = append(names, conts[i].Name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user