mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 22:38:45 +00:00
53 lines
1013 B
Go
53 lines
1013 B
Go
package events
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/remeh/sizedwaitgroup"
|
|
"github.com/runatlantis/atlantis/server/events/models"
|
|
)
|
|
|
|
type prjCmdRunnerFunc func(ctx models.ProjectCommandContext) models.ProjectResult
|
|
|
|
func runProjectCmdsParallel(
|
|
cmds []models.ProjectCommandContext,
|
|
runnerFunc prjCmdRunnerFunc,
|
|
poolSize int,
|
|
) CommandResult {
|
|
var results []models.ProjectResult
|
|
mux := &sync.Mutex{}
|
|
|
|
wg := sizedwaitgroup.New(poolSize)
|
|
for _, pCmd := range cmds {
|
|
pCmd := pCmd
|
|
var execute func()
|
|
wg.Add()
|
|
|
|
execute = func() {
|
|
defer wg.Done()
|
|
res := runnerFunc(pCmd)
|
|
mux.Lock()
|
|
results = append(results, res)
|
|
mux.Unlock()
|
|
}
|
|
|
|
go execute()
|
|
}
|
|
|
|
wg.Wait()
|
|
return CommandResult{ProjectResults: results}
|
|
}
|
|
|
|
func runProjectCmds(
|
|
cmds []models.ProjectCommandContext,
|
|
runnerFunc prjCmdRunnerFunc,
|
|
) CommandResult {
|
|
var results []models.ProjectResult
|
|
for _, pCmd := range cmds {
|
|
res := runnerFunc(pCmd)
|
|
|
|
results = append(results, res)
|
|
}
|
|
return CommandResult{ProjectResults: results}
|
|
}
|