class PrettyMultitask::Runner

This class will run multiple callables in parallel using RunCallable which add a nice format

Public Class Methods

new(jobs) click to toggle source
# File lib/pretty_multitask/runner.rb, line 7
def initialize(jobs)
  @jobs = jobs
  @jobs.each do |j|
    %i[name cmd].each { |o| raise "#{o} must be specified for job #{j}" unless j[o] }
    j[:out_file] = "/tmp/#{j[:name]}-#{Time.now.strftime('%s.%N')}"
    FileUtils.touch j[:out_file]
  end
end

Public Instance Methods

longest_jobname() click to toggle source
# File lib/pretty_multitask/runner.rb, line 49
def longest_jobname
  longest = 0
  @jobs.each { |job| longest = job[:name].length if job[:name].length > longest }
  longest
end
print_out() click to toggle source
run() click to toggle source
# File lib/pretty_multitask/runner.rb, line 16
def run
  exec = Tlopo::Executor.new 10

  @jobs.each { |job| job[:padding] = longest_jobname }
  @jobs.each do |j|
    task = proc { j[:exit_status] = RunCallable.new(j).run }
    exec.schedule task
  end
  errors = exec.run.errors

  print_out

  unless errors.empty?
    errors.each { |e| LOGGER.error e }
    raise 'Found errors'
  end
end