Sha256: 3e9138552273c3d7559f8712ff33978070fa18172a0888d2137d6d0fd4f850d3

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Outliers
  class Run
    attr_accessor :account, :results, :threads, :threaded, :thread_count

    def initialize(options={})
      @results                  = []
      @threads                  = []
      @threaded                 = false
      @thread_count             = 1
      Thread.abort_on_exception = true
    end

    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=nil, &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 }

      if name
        logger.info "Loading evaluation '#{name}'."
      else
        logger.info "Loading unnamed evaluation."
      end

      threaded ? threads << Thread.new { evaluation.call } : evaluation.call
    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
outliers-0.6.0 lib/outliers/run.rb