Class: Upperkut::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/upperkut/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Manager

Returns a new instance of Manager.



10
11
12
13
14
15
16
17
# File 'lib/upperkut/manager.rb', line 10

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

  @stopped = false
  @processors = []
end

Instance Attribute Details

#concurrencyObject (readonly)

Returns the value of attribute concurrency.



8
9
10
# File 'lib/upperkut/manager.rb', line 8

def concurrency
  @concurrency
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/upperkut/manager.rb', line 8

def logger
  @logger
end

#processorsObject (readonly)

Returns the value of attribute processors.



8
9
10
# File 'lib/upperkut/manager.rb', line 8

def processors
  @processors
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



8
9
10
# File 'lib/upperkut/manager.rb', line 8

def stopped
  @stopped
end

#workerObject

Returns the value of attribute worker.



7
8
9
# File 'lib/upperkut/manager.rb', line 7

def worker
  @worker
end

Instance Method Details

#killObject



31
32
33
# File 'lib/upperkut/manager.rb', line 31

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

#notify_killed_processor(processor) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/upperkut/manager.rb', line 35

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

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

#runObject



19
20
21
22
23
24
25
# File 'lib/upperkut/manager.rb', line 19

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

#stopObject



27
28
29
# File 'lib/upperkut/manager.rb', line 27

def stop
  @stopped = true
end