Module: WarouzServer::WorkerManager

Included in:
Master
Defined in:
lib/warouz_server/worker_manager.rb

Instance Method Summary collapse

Instance Method Details

#start_workersObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/warouz_server/worker_manager.rb', line 3

def start_workers
  for cl in 1..WarouzServer::WORKERS 
    worker =  WarouzServer::Worker.new
    worker_thread=Thread.new do
      begin
        worker.start
      rescue Exception=>e
        logger.error(e)
      end
    end
    worker_instances << worker
    worker_threads << worker_thread
  end
  nil
end

#stop_worker_threadsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/warouz_server/worker_manager.rb', line 19

def stop_worker_threads
  return if worker_threads.empty?
  worker_instances.each do |worker_instance|
    worker_instance.stop
  end
  worker_threads.each do |worker_thread|
    worker_thread.join(5)
    if worker_thread.alive?
      worker_thread.terminate
      logger.warn("#{worker_thread.object_id} was to slow to stop, killed.")
    else
      logger.info("#{worker_thread.object_id} stopped.")
    end
  end
  nil
end