Sha256: ac0c9e532885ea03c1bd8f91d15b7c552273632f0c348c43d73a071219e6d9e9

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

module DeepTest
  class LocalWorkers
    
    def initialize(options)
      @options = options
      @warlock = Warlock.new
    end

    def load_files(files)
      files.each {|f| load f}
    end
    
    def server
      @options.server
    end

    def start_all(s)
      each_worker do |worker_num|
        start_worker(worker_num) do
          reseed_random_numbers
          reconnect_to_database
          worker = DeepTest::Worker.new(worker_num,
                                        server, 
                                        @options.new_listener_list)
          worker.run
        end
      end        
    end

    def stop_all
      @warlock.stop_all
    end

    def number_of_workers
      @options.number_of_workers
    end

    private

    def reconnect_to_database
      ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
    end

    def start_worker(worker_num, &blk)
      @warlock.start("worker #{worker_num}", &blk)
    end

    def reseed_random_numbers
      srand
    end

    def each_worker
      number_of_workers.to_i.times { |worker_num| yield worker_num }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jason-o-matic-deep_test-1.2.2.10 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.11 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.12 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.13 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.14 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.5 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.6 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.7 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.8 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.9 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.15 lib/deep_test/local_workers.rb