lib/outliers/run.rb in outliers-0.2.0 vs lib/outliers/run.rb in outliers-0.3.0

- old
+ new

@@ -1,26 +1,37 @@ module Outliers class Run - attr_accessor :credentials, :results + attr_accessor :credentials, :results, :threads, :threaded, :thread_count - def initialize - @results = [] + def initialize(options={}) + @results = [] + @threads = [] + @threaded = false + @thread_count = 1 + Thread.abort_on_exception = true end - def process_evaluations_in_config_folder - evaluations_path = File.join Outliers.config_path - files = Dir.glob(File.join(evaluations_path, '**', '*')) + def process_evaluations_in_dir files.each do |file| next if File.directory? file next if File.extname(file) != '.rb' logger.info "Processing '#{file}'." self.instance_eval File.read(file) end + + threads.each {|t| t.join} end def evaluate(name='unspecified', &block) - Evaluation.new(:name => name, :run => self).instance_eval &block + while Thread.list.count > thread_count + logger.info "Maximum concurrent threads running, sleeping." + sleep 2 + end + + evaluation = Proc.new { Evaluation.new(:name => name, :run => self).instance_eval &block } + + threaded ? threads << Thread.new { evaluation.call } : evaluation.call end def passed @results.select {|r| r.passed?} end @@ -28,9 +39,14 @@ def failed @results.reject {|r| r.passed?} end private + + def files + evaluations_path = File.join Outliers.config_path + files = Dir.glob File.join(evaluations_path, '**', '*') + end def logger @logger ||= Outliers.logger end