Class: Daemonizer::WorkerPool
- Inherits:
-
Object
- Object
- Daemonizer::WorkerPool
- Defined in:
- lib/daemonizer/worker_pool.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check_workers ⇒ Object
-
#initialize(name, pm, &blk) ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #shutdown? ⇒ Boolean
- #start_workers(number) ⇒ Object
- #stop_workers(force) ⇒ Object
- #wait_workers ⇒ Object
Constructor Details
#initialize(name, pm, &blk) ⇒ WorkerPool
Returns a new instance of WorkerPool.
5 6 7 8 9 10 |
# File 'lib/daemonizer/worker_pool.rb', line 5 def initialize(name, pm, &blk) @name = name @pm = pm @worker_block = blk @workers = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/daemonizer/worker_pool.rb', line 3 def name @name end |
Instance Method Details
#check_workers ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/daemonizer/worker_pool.rb', line 23 def check_workers Daemonizer.logger.debug "Checking loop #{name} workers..." @workers.each do |worker| next if worker.running? || worker.shutdown? Daemonizer.logger.warn "Worker #{worker.name} is not running. Restart!" worker.run end end |
#shutdown? ⇒ Boolean
12 13 14 |
# File 'lib/daemonizer/worker_pool.rb', line 12 def shutdown? @pm.shutdown? end |
#start_workers(number) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/daemonizer/worker_pool.rb', line 16 def start_workers(number) Daemonizer.logger.debug "Creating #{number} workers for #{name} pool..." number.times do |i| @workers << Worker.new(name, @pm, i+1, &@worker_block) end end |
#stop_workers(force) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/daemonizer/worker_pool.rb', line 42 def stop_workers(force) Daemonizer.logger.debug "Stopping #{name} pool workers..." @workers.each do |worker| next unless worker.running? worker.stop(force) end end |
#wait_workers ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/daemonizer/worker_pool.rb', line 32 def wait_workers running = 0 @workers.each do |worker| next unless worker.running? running += 1 Daemonizer.logger.debug "Worker #{name} is still running (#{worker.pid})" end return running end |