class Upperkut::Manager

Attributes

concurrency[R]
logger[R]
stopped[R]
worker[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/upperkut/manager.rb, line 11
def initialize(opts = {})
  self.worker = opts.fetch(:worker).constantize
  @concurrency = opts.fetch(:concurrency, 1)
  @logger = opts.fetch(:logger, Logging.logger)

  @stopped = false
  @threads = []
end

Public Instance Methods

kill() click to toggle source
# File lib/upperkut/manager.rb, line 31
def kill
  @threads.each(&:kill)
end
notify_killed_processor(thread) click to toggle source
# File lib/upperkut/manager.rb, line 35
def notify_killed_processor(thread)
  @threads.delete(thread)
  spawn_thread unless @stopped
end
run() click to toggle source
# File lib/upperkut/manager.rb, line 20
def run
  @concurrency.times do
    spawn_thread
  end
end
stop() click to toggle source
# File lib/upperkut/manager.rb, line 26
def stop
  @stopped = true
  @threads.each(&:stop)
end

Private Instance Methods

spawn_thread() click to toggle source
# File lib/upperkut/manager.rb, line 42
def spawn_thread
  processor = Processor.new(worker, logger)

  thread = WorkerThread.new(self, processor)
  @threads << thread
  thread.run
end