Sha256: e443f1c75d7e11975de3c0f9c24fd16949e2edff97c090638bcf8b02b36d1db2

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 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
      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

13 entries across 13 versions & 4 rubygems

Version Path
jason-o-matic-deep_test-1.2.2.1 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.2 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.3 lib/deep_test/local_workers.rb
jason-o-matic-deep_test-1.2.2.4 lib/deep_test/local_workers.rb
jperkins-deep_test-1.2.2 lib/deep_test/local_workers.rb
jstorimer-deep-test-1.4.0 lib/deep_test/local_workers.rb
jstorimer-deep-test-1.3.0 lib/deep_test/local_workers.rb
jstorimer-deep-test-1.2.0 lib/deep_test/local_workers.rb
jstorimer-deep-test-1.1.0 lib/deep_test/local_workers.rb
jstorimer-deep-test-1.0.0 lib/deep_test/local_workers.rb
deep_test-1.2.0 lib/deep_test/local_workers.rb
deep_test-1.2.2 lib/deep_test/local_workers.rb
deep_test-1.2.1 lib/deep_test/local_workers.rb