Skip to content

Commit

Permalink
Merge pull request #207 from boltops-tools/dont-fork
Browse files Browse the repository at this point in the history
dont fork when all.concurrency = 1
  • Loading branch information
tongueroo authored Feb 17, 2022
2 parents 4643e5a + 28ed963 commit 1e871ad
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/terraspace/all/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,27 @@ def deploy_batch(batch)
concurrency = Terraspace.config.all.concurrency
batch.sort_by(&:name).each_slice(concurrency) do |slice|
slice.each do |node|
pid = fork do
build_stack(node.name)
run_terraspace(node.name)
if fork?
pid = fork do
deploy_stack(node)
end
@pids[pid] = node.name # store mod_name mapping
else
deploy_stack(node)
end
@pids[pid] = node.name # store mod_name mapping
end
end
return unless fork?
wait_for_child_proccess
summarize # also reports lower-level error info
report_errors # reports finall errors and possibly exit
end

def deploy_stack(node)
build_stack(node.name)
run_terraspace(node.name)
end

def build_modules
builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", clean: true, quiet: true, include_stacks: :none))
builder.build(modules: true)
Expand Down Expand Up @@ -109,7 +118,7 @@ def summarize
end

def run_terraspace(mod_name)
set_log_path!(mod_name)
set_log_path!(mod_name) if fork?
name = command_map(@command)
o = @options.merge(mod: mod_name, yes: true, build: false, input: false, log_to_stderr: true)
o.merge!(quiet: false) if @command == "init" # noisy so can filter and summarize output
Expand All @@ -123,6 +132,10 @@ def run_terraspace(mod_name)
end
end

def fork?
Terraspace.config.all.concurrency > 1
end

def set_log_path!(mod_name)
command = terraspace_command(mod_name)
path = log_path(mod_name)
Expand Down

0 comments on commit 1e871ad

Please sign in to comment.