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.



11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#concurrencyObject (readonly)

Returns the value of attribute concurrency.



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

def concurrency
  @concurrency
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



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

def stopped
  @stopped
end

#workerObject

Returns the value of attribute worker.



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

def worker
  @worker
end

Instance Method Details

#killObject



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

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

#notify_killed_processor(thread) ⇒ Object



35
36
37
38
# File 'lib/upperkut/manager.rb', line 35

def notify_killed_processor(thread)
  @threads.delete(thread)
  spawn_thread unless @stopped
end

#runObject



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

def run
  @concurrency.times do
    spawn_thread
  end
end

#stopObject



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

def stop
  @stopped = true
  @threads.each(&:stop)
end