feat: support parallel with execution order groups (#2403)

This commit is contained in:
Andrei Vydrin
2022-09-08 20:14:59 +07:00
committed by GitHub
parent 9f31e49be8
commit 2d7ee9dfa8
4 changed files with 40 additions and 3 deletions

View File

@@ -214,6 +214,8 @@ projects:
```
With this config above, Atlantis runs planning/applying for project2 first, then for project1.
Several projects can have same `execution_order_group`. Any order in one group isn't guaranteed.
`parallel_plan` and `parallel_apply` respect these order groups, so parallel planning/applying works
in each group one by one.
### Custom Backend Config
See [Custom Workflow Use Cases: Custom Backend Config](custom-workflows.html#custom-backend-config)

View File

@@ -144,7 +144,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) {
var result command.Result
if a.isParallelEnabled(projectCmds) {
ctx.Log.Info("Running applies in parallel")
result = runProjectCmdsParallel(projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize)
result = runProjectCmdsParallelGroups(projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize)
} else {
result = runProjectCmds(projectCmds, a.prjCmdRunner.Apply)
}

View File

@@ -110,7 +110,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) {
var result command.Result
if p.isParallelEnabled(projectCmds) {
ctx.Log.Info("Running plans in parallel")
result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize)
result = runProjectCmdsParallelGroups(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize)
} else {
result = runProjectCmds(projectCmds, p.prjCmdRunner.Plan)
}
@@ -184,7 +184,7 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) {
var result command.Result
if p.isParallelEnabled(projectCmds) {
ctx.Log.Info("Running applies in parallel")
result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize)
result = runProjectCmdsParallelGroups(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize)
} else {
result = runProjectCmds(projectCmds, p.prjCmdRunner.Plan)
}

View File

@@ -1,6 +1,7 @@
package events
import (
"sort"
"sync"
"github.com/remeh/sizedwaitgroup"
@@ -50,3 +51,37 @@ func runProjectCmds(
}
return command.Result{ProjectResults: results}
}
func splitByExecutionOrderGroup(cmds []command.ProjectContext) [][]command.ProjectContext {
groups := make(map[int][]command.ProjectContext)
for _, cmd := range cmds {
groups[cmd.ExecutionOrderGroup] = append(groups[cmd.ExecutionOrderGroup], cmd)
}
var groupKeys []int
for k := range groups {
groupKeys = append(groupKeys, k)
}
sort.Ints(groupKeys)
var res [][]command.ProjectContext
for _, group := range groupKeys {
res = append(res, groups[group])
}
return res
}
func runProjectCmdsParallelGroups(
cmds []command.ProjectContext,
runnerFunc prjCmdRunnerFunc,
poolSize int,
) command.Result {
var results []command.ProjectResult
groups := splitByExecutionOrderGroup(cmds)
for _, group := range groups {
res := runProjectCmdsParallel(group, runnerFunc, poolSize)
results = append(results, res.ProjectResults...)
}
return command.Result{ProjectResults: results}
}