lib/spool/pool.rb in spool-1.0.4 vs lib/spool/pool.rb in spool-1.0.5

- old
+ new

@@ -54,20 +54,24 @@ end logger.info(self.class) { "SPOOL START => #{format_processes}" } while running? - action = actions_queue.pop - - if action - logger.info(self.class) { "Starting action #{action[:name]} with params: [#{action[:args].join(', ')}]" } - send action[:name], *action[:args] - end + begin + action = actions_queue.pop + + if action + logger.info(self.class) { "Starting action #{action[:name]} with params: [#{action[:args].join(', ')}]" } + send action[:name], *action[:args] + end - if running? - check_status - sleep CHECK_TIMEOUT + if running? + check_status + sleep CHECK_TIMEOUT + end + rescue Exception => e + log_error e end end logger.info(self.class) { "Spool finished successfully!" } end @@ -96,22 +100,19 @@ (configuration.processes - all_processes_count).times do working_processes << Spawner.spawn(configuration) end - logger.info(self.class) { "Status after new childrens => #{format_processes}}" } + logger.info(self.class) { "Status after new childrens => #{format_processes}" } elsif configuration.processes < working_processes.count count_to_kill = working_processes.count - configuration.processes logger.info(self.class) { "Killing #{count_to_kill} children. Current state => #{format_processes}" } stop_processes working_processes.take(count_to_kill) logger.info(self.class) { "After killing childers. Current State => #{format_processes}" } end - - rescue Exception => e - log_error e end def _incr(count=1) configuration.processes += count end @@ -128,19 +129,16 @@ def _restart logger.info(self.class) { "RESTART" } stop_processes working_processes end - def _stop(timeout=0) + def _stop logger.info(self.class) { "SPOOL STOP" } stop_processes working_processes - Timeout.timeout(timeout) { wait_for_stopped all_processes } - rescue Timeout::Error - logger.error(self.class) { "ERROR IN SPOOL STOP. Timeout error" } - ensure - _stop! + wait_for_stopped all_processes + @running = false end def _stop! logger.info(self.class) { "SPOOL STOP! Going to kill => #{format_processes}" } @@ -152,15 +150,13 @@ log_error e end end wait_for_stopped all_processes - - working_processes.clear - zombie_processes.clear - + File.delete configuration.pid_file if File.exist? configuration.pid_file + @running = false end def stop_processes(processes_list) processes_list.each do |p| @@ -177,9 +173,11 @@ def wait_for_stopped(processes_list) while processes_list.any?(&:alive?) sleep 0.01 end + + clear_dead_processes end def check_processes_to_restart to_restart = working_processes.select(&configuration.restart_condition)