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
18
# File 'lib/upperkut/manager.rb', line 10

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

  @stopped = false
  @processors = []
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#redisObject

Returns the value of attribute redis.



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

def redis
  @redis
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



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

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

#notify_killed_processor(processor) ⇒ Object



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

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

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

#runObject



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

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

#stopObject



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

def stop
  @stopped = true
end