Method: Delayed::Command#daemonize

Defined in:
lib/delayed/command.rb

#daemonizeObject

[View source]

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/delayed/command.rb', line 60

def daemonize
  Delayed::Worker.backend.before_fork

  ObjectSpace.each_object(File) do |file|
    @files_to_reopen << file unless file.closed?
  end
  
  dir = @options[:pid_dir]
  Dir.mkdir(dir) unless File.exists?(dir)
  
  if @worker_count > 1 && @options[:identifier]
    raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
  elsif @worker_count == 1 && @options[:identifier]
    process_name = "delayed_job.#{@options[:identifier]}"
    run_process(process_name, dir)
  else
    worker_count.times do |worker_index|
      process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
      run_process(process_name, dir)
    end
  end
end