lib/larva/worker_pool.rb in larva-0.9.0 vs lib/larva/worker_pool.rb in larva-0.9.1

- old
+ new

@@ -8,13 +8,19 @@ def initialize(processors) @processors = processors end def start + @running = true start_workers - keep_workers_alive if workers.count > 0 + keep_workers_alive if workers.count > 0 end + + def stop + logger.info "Request to stop worker pool accepted" + @running = false + end private def start_workers logger.info "Starting #{processors.count} threads." @workers = processors.map do |topic, processor| @@ -30,18 +36,19 @@ rescue => e logger.error "Unexpected listener termination: #{e} #{e.backtrace}" end def keep_workers_alive - while workers.all? { |t| t.alive? } + while @running && workers.all? { |t| t.alive? } logger.info 'All threads are alive.' sleep(60) end logger.error 'Some threads have died:' workers.each do |worker| logger.error "#{worker[:name]} was #{worker.alive? ? 'alive' : 'dead'}" end + raise StandardError.new('Some threads have died') if @running end def logger Propono.config.logger end