lib/aws_cft_tools/runbooks/deploy.rb in aws-cft-tools-0.1.0 vs lib/aws_cft_tools/runbooks/deploy.rb in aws-cft-tools-0.1.1
- old
+ new
@@ -46,22 +46,39 @@
def process_templates(slice_size)
templates_in_folder_order.each_slice(slice_size, &method(:process_slice))
end
def process_slice(templates)
- old_stdout = $stdout
- threads = create_threads(templates) { |template| process_template(template) }
- threads.map(&:thread).map(&:join)
- puts threads.map(&:output).map(&:string)
+ jobs = options[:jobs]
+ if jobs && jobs > 1
+ process_slice_threaded(templates)
+ else
+ templates.each(&method(:process_template))
+ end
+ end
+
+ def process_slice_threaded(templates)
+ original_stdout = $stdout
+ $stdout = ThreadedOutput.new(original_stdout)
+ template_list = templates.map(&:name).join(', ')
+ debug("Creating threads for #{template_list}")
+ threads = create_threads(templates, &method(:process_template))
+ debug("Waiting on threads for #{template_list}")
+ threads.map(&:join)
ensure
- $stdout = old_stdout # just in case!
+ $stdout = original_stdout
end
def process_template(template)
+ ThreadedOutput.prefix = template_name = template.name
+ debug("Processing #{template_name}")
is_update = deployed_templates.include?(template)
- operation("#{is_update ? 'Updating' : 'Creating'}: #{template.name}") do
+ operation("#{is_update ? 'Updating' : 'Creating'}: #{template_name}") do
exec_template(template: template, type: is_update ? :update : :create)
end
+ ensure
+ $stdout.flush
+ debug("Finished processing #{template_name}")
end
def exec_template(params) # template:, type:
checking { exec_template_check(**params) }
doing { exec_template_for_real(**params) }