Method: Spool::Pool#start

Defined in:
lib/spool/pool.rb

#startObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/spool/pool.rb', line 45

def start
  @running = true

  handle_signals

  File.write configuration.pid_file, Process.pid if configuration.pid_file

  configuration.processes.times.map do
    working_processes << Spawner.spawn(configuration)
  end

  logger.info(self.class) { "SPOOL START => #{format_processes}" }

  while running?
    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
      end
    rescue Exception => e
      log_error e
    end
  end

  logger.info(self.class) { "Spool finished successfully!" }
end