Sha256: b408079115d28139dc1e8565423f18a62c1cc16ff292f4d161c26ca39730a370

Contents?: true

Size: 892 Bytes

Versions: 8

Compression:

Stored size: 892 Bytes

Contents

class TaskManager
 
  def initialize(output)
    @output = output
    @tasks = []
  end
  
  def add(task)
    @tasks << task
  end
  
  def run(files)
    @num_tasks_run = 0
    
    @tasks.each do |task|
      
      begin
        break if !run_task(files, task)        
      rescue Exception => ex
        output_exception(ex)
      end
      
    end
  end
  
  def run_task(files, task)
    result = task.run(files)
    return true if result.nil?

    task_run
      
    @output.add_result(result) 
    return !([:error, :failure].include? result[:state])
  end
  
  def task_run
    @num_tasks_run += 1
    if (@num_tasks_run == 1) 
      @output.start_run
    end  
  end
  
  def output_exception(ex)
    @output.add_result({
      :state => :error,
      :title => 'Task',
      :summary => 'Exception',
      :first => ex.message,
      :detail => ex.backtrace
    })
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
loris-0.1.4 lib/task_manager.rb
loris-0.1.3 lib/task_manager.rb
loris-0.1.2 lib/task_manager.rb
loris-0.1.1 lib/task_manager.rb
loris-0.1.0 lib/task_manager.rb
loris-0.0.16 lib/task_manager.rb
loris-0.0.15 lib/task_manager.rb
loris-0.0.14 lib/task_manager.rb