Method: Molder::App#execute!

Defined in:
lib/molder/app.rb

#execute!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/molder/app.rb', line 23

def execute!
    colors = %i(yellow blue red green magenta cyan white)

    FileUtils.mkdir_p(log_dir)
    if options.dry_run
      puts "\nDry-run print of #{commands.size} commands:\n".bold.cyan.underlined
      commands.count.times do |i|
        color = colors[i % colors.size]
        cmd   = commands[i ]
        puts "#{cmd}\n".send(color).send(:bold)
      end
    else
      puts "Executing #{commands.size} commands using a pool of up to #{options.max_processes} processes:\n".bold.cyan.underlined
      ::Parallel.each((1..commands.size),
                      :in_processes => options.max_processes) do |i|

        color = colors[(i - 1) % colors.size]
        cmd   = commands[i - 1]
        printf('%s', "Worker: #{Parallel.worker_number}, command #{i}\n".send(color)) if options.verbose
        puts "#{cmd}\n".send(color)

        system %Q(( #{cmd} ) > #{log_dir}/#{command_name}.#{i}.log)
    end
  end
end