Sha256: 14ac428cfcaa66ef70837294b0fa08375dc3c1133d613ce90fdf60d0bb2a886f

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

require_relative 'core_ext'
require_relative 'processor'
require_relative 'worker'

module Upperkut
  class Manager
    attr_accessor :worker
    attr_reader :stopped, :logger

    def initialize(opts = {})
      self.worker = opts.fetch(:worker).constantize
      @concurrency = opts.fetch(:concurrency, 25)
      @logger = opts.fetch(:logger, Upperkut::Logging.logger)

      @stopped = false
      @processors = []
    end

    def run
      @concurrency.times do
        processor = Processor.new(self)
        @processors << processor
        processor.run
      end
    end

    def stop
      @stopped = true
    end

    def kill
      @processors.each(&:kill)
    end

    def notify_killed_processor(processor)
      @processors.delete(processor)
      return if @stopped

      processor = Processor.new(self)
      @processors << processor
      processor.run
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upperkut-0.5.1 lib/upperkut/manager.rb