mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
terraform: ContextOpts can set a max parallelism
This commit is contained in:
parent
7f86bcb873
commit
3318fe97dc
@ -30,6 +30,7 @@ type Context struct {
|
||||
variables map[string]string
|
||||
|
||||
l sync.Mutex // Lock acquired during any task
|
||||
parCh chan struct{} // Semaphore used to limit parallelism
|
||||
sl sync.RWMutex // Lock acquired to R/W internal data
|
||||
runCh <-chan struct{}
|
||||
sh *stopHook
|
||||
@ -41,6 +42,7 @@ type ContextOpts struct {
|
||||
Config *config.Config
|
||||
Diff *Diff
|
||||
Hooks []Hook
|
||||
Parallelism int
|
||||
State *State
|
||||
Providers map[string]ResourceProviderFactory
|
||||
Variables map[string]string
|
||||
@ -60,6 +62,13 @@ func NewContext(opts *ContextOpts) *Context {
|
||||
copy(hooks, opts.Hooks)
|
||||
hooks[len(opts.Hooks)] = sh
|
||||
|
||||
// Make the parallelism channel
|
||||
par := opts.Parallelism
|
||||
if par == 0 {
|
||||
par = 10
|
||||
}
|
||||
parCh := make(chan struct{}, par)
|
||||
|
||||
return &Context{
|
||||
config: opts.Config,
|
||||
diff: opts.Diff,
|
||||
@ -68,6 +77,7 @@ func NewContext(opts *ContextOpts) *Context {
|
||||
providers: opts.Providers,
|
||||
variables: opts.Variables,
|
||||
|
||||
parCh: parCh,
|
||||
sh: sh,
|
||||
}
|
||||
}
|
||||
@ -682,6 +692,12 @@ func (c *Context) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Limit parallelism
|
||||
c.parCh <- struct{}{}
|
||||
defer func() {
|
||||
<-c.parCh
|
||||
}()
|
||||
|
||||
switch m := n.Meta.(type) {
|
||||
case *GraphNodeResource:
|
||||
// Continue, we care about this the most
|
||||
|
Loading…
Reference in New Issue
Block a user