Sha256: 1b62a4b02fe814551110fbec265b8308fde38fefbda7bb40e55b40f62036bc65

Contents?: true

Size: 1.17 KB

Versions: 26

Compression:

Stored size: 1.17 KB

Contents

module Daemonizer
  class WorkerPool
    attr_reader :name

    def initialize(name, pm, &blk)
      @name = name
      @pm = pm
      @worker_block = blk
      @workers = []
    end

    def shutdown?
      @pm.shutdown?
    end

    def start_workers(number)
      Daemonizer.logger.debug "Creating #{number} workers for #{name} pool..."
      number.times do |i|
        @workers << Worker.new(name, @pm, i+1, &@worker_block)
      end
    end

    def check_workers
      Daemonizer.logger.debug "Checking loop #{name} workers..."
      @workers.each do |worker|
        next if worker.running? || worker.shutdown?
        Daemonizer.logger.warn "Worker #{worker.name} is not running. Restart!"
        worker.run
      end
    end

    def wait_workers
      running = 0
      @workers.each do |worker|
        next unless worker.running?
        running += 1
        Daemonizer.logger.debug "Worker #{name} is still running (#{worker.pid})"
      end
      return running
    end

    def stop_workers(force)
      Daemonizer.logger.debug "Stopping #{name} pool workers..."
      @workers.each do |worker|
        next unless worker.running?
        worker.stop(force)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
daemonizer-0.4.12 lib/daemonizer/worker_pool.rb
daemonizer-0.4.11 lib/daemonizer/worker_pool.rb
daemonizer-0.4.10 lib/daemonizer/worker_pool.rb
daemonizer-0.4.9 lib/daemonizer/worker_pool.rb
daemonizer-0.4.8 lib/daemonizer/worker_pool.rb
daemonizer-0.4.7 lib/daemonizer/worker_pool.rb
daemonizer-0.4.6 lib/daemonizer/worker_pool.rb
daemonizer-0.4.5 lib/daemonizer/worker_pool.rb
daemonizer-0.4.4 lib/daemonizer/worker_pool.rb
daemonizer-0.4.3 lib/daemonizer/worker_pool.rb
daemonizer-0.4.2 lib/daemonizer/worker_pool.rb
daemonizer-0.4.1 lib/daemonizer/worker_pool.rb
daemonizer-0.4.0 lib/daemonizer/worker_pool.rb
daemonizer-0.3.10 lib/daemonizer/worker_pool.rb
daemonizer-0.3.9 lib/daemonizer/worker_pool.rb
daemonizer-0.3.8 lib/daemonizer/worker_pool.rb
daemonizer-0.3.7 lib/daemonizer/worker_pool.rb
daemonizer-0.3.6 lib/daemonizer/worker_pool.rb
daemonizer-0.3.5 lib/daemonizer/worker_pool.rb
daemonizer-0.3.4 lib/daemonizer/worker_pool.rb