module Procrastinator::QueueManager::ChildMethods

Methods exclusive to the child process

Public Instance Methods

close_io() click to toggle source

Make sure all input/output streams are closed

# File lib/procrastinator/queue_manager.rb, line 130
def close_io
   stds = [$stdin, $stdout, $stderr]

   # Part 1: close all IO objects (except for $stdin/$stdout/$stderr)
   ObjectSpace.each_object(IO) do |io|
      next if stds.include?(io)

      begin
         io.close
      rescue IOError
         next
      end
   end

   # Part 2: redirect STD connections
   stds.each do |io|
      io.reopen '/dev/null'
   end

   # TODO: redirect OUT or ERR to logger?
end
deamonize(name) click to toggle source
# File lib/procrastinator/queue_manager.rb, line 117
def deamonize(name)
   Process.daemon(true)
   Process.setsid
   srand
   Process.setproctitle(name)
   close_io

   write_pid_file(Process.pid, name)

   @config.run_process_block
end
shutdown_worker() click to toggle source

Wrapping exit to allow for tests to easily stub out this behaviour. If exit isn't prevented, the test framework will break, but exit can't be directly stubbed either (because it's a required Kernel method)

# File lib/procrastinator/queue_manager.rb, line 155
def shutdown_worker
   exit
end