mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 20:48:37 +00:00
* Moved CommandContext and CommandResult to models (#193) * Moved CommandContext and CommandResult to models * move from models to command rename CommandContext -> Context rename CommandResult -> Result * moved command related helpers into command package * move ProjectCommandContext and ProjectResult to command/project package * move project command context and project result * revert unrelated code * move tests * fix left over * fix linting * fix tests * remove unused import * fix project context dependencies * fix depenedecies * fix typo
53 lines
1003 B
Go
53 lines
1003 B
Go
package events
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/remeh/sizedwaitgroup"
|
|
"github.com/runatlantis/atlantis/server/events/command"
|
|
)
|
|
|
|
type prjCmdRunnerFunc func(ctx command.ProjectContext) command.ProjectResult
|
|
|
|
func runProjectCmdsParallel(
|
|
cmds []command.ProjectContext,
|
|
runnerFunc prjCmdRunnerFunc,
|
|
poolSize int,
|
|
) command.Result {
|
|
var results []command.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 command.Result{ProjectResults: results}
|
|
}
|
|
|
|
func runProjectCmds(
|
|
cmds []command.ProjectContext,
|
|
runnerFunc prjCmdRunnerFunc,
|
|
) command.Result {
|
|
var results []command.ProjectResult
|
|
for _, pCmd := range cmds {
|
|
res := runnerFunc(pCmd)
|
|
|
|
results = append(results, res)
|
|
}
|
|
return command.Result{ProjectResults: results}
|
|
}
|