Commit 3c8dd4cc authored by Matija Čupić's avatar Matija Čupić

Move parallelization to Ci::Config::Normalizer

parent 8f8a89f9
......@@ -29,15 +29,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def compose!(deps = nil)
super do
@config = @config.map do |name, config|
total = config[:parallel]
if total
Array.new(total) { { name => config } }
.each_with_index { |build, idx| build["#{name} #{idx + 1}/#{total}".to_sym] = build.delete(name) }
else
{ name => config }
end
end.flatten.reduce(:merge)
@config = Ci::Config::Normalizer.normalize_jobs(@config)
@config.each do |name, config|
node = hidden?(name) ? Entry::Hidden : Entry::Job
......
module Gitlab
module Ci
class Config
class Normalizer
class << self
def normalize_jobs(jobs_config)
parallelized_jobs = {}
parallelized_config = jobs_config.map do |name, config|
if config&.[](:parallel)
total = config[:parallel]
names = parallelize_job_names(name, total)
parallelized_jobs[name] = names
Hash[names.collect { |job_name| [job_name.to_sym, config] }]
else
{ name => config }
end
end.reduce(:merge)
parallelized_config.each do |name, config|
next unless config[:dependencies]
deps = config[:dependencies].map do |dep|
if parallelized_jobs.keys.include?(dep.to_sym)
config[:dependencies].delete(dep)
parallelized_jobs[dep.to_sym]
else
dep
end
end.flatten
config[:dependencies] = deps
end
end
private
def parallelize_job_names(name, total)
jobs = []
total.times do |idx|
jobs << "#{name} #{idx + 1}/#{total}"
end
jobs
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment