Method: Delayed::Command#initialize

Defined in:
lib/delayed/command.rb

#initialize(args) ⇒ Command

Returns a new instance of Command.

[View source]

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/delayed/command.rb', line 9

def initialize(args)
  @files_to_reopen = []
  @options = {
    :quiet => true,
    :pid_dir => "#{RAILS_ROOT}/tmp/pids"
  }
  
  @worker_count = 1
  @monitor = false
  
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run"

    opts.on('-h', '--help', 'Show this message') do
      puts opts
      exit 1
    end
    opts.on('-e', '--environment=NAME', 'Specifies the environment to run this delayed jobs under (test/development/production).') do |e|
      STDERR.puts "The -e/--environment option has been deprecated and has no effect. Use RAILS_ENV and see http://github.com/collectiveidea/delayed_job/issues/#issue/7"
    end
    opts.on('--min-priority N', 'Minimum priority of jobs to run.') do |n|
      @options[:min_priority] = n
    end
    opts.on('--max-priority N', 'Maximum priority of jobs to run.') do |n|
      @options[:max_priority] = n
    end
    opts.on('-n', '--number_of_workers=workers', "Number of unique workers to spawn") do |worker_count|
      @worker_count = worker_count.to_i rescue 1
    end
    opts.on('--pid-dir=DIR', 'Specifies an alternate directory in which to store the process ids.') do |dir|
      @options[:pid_dir] = dir
    end
    opts.on('-i', '--identifier=n', 'A numeric identifier for the worker.') do |n|
      @options[:identifier] = n
    end
    opts.on('-m', '--monitor', 'Start monitor process.') do
      @monitor = true
    end
    opts.on('--sleep-delay N', "Amount of time to sleep when no jobs are found") do |n|
      @options[:sleep_delay] = n
    end
    opts.on('--queues=queues', "Specify which queue DJ must look up for jobs") do |queues|
      @options[:queues] = queues.split(/\s*,\s*/)
    end
    opts.on('--queue=queue', "Specify which queue DJ must look up for jobs") do |queue|
      @options[:queues] = queue.split(/\s*,\s*/)
    end
  end
  @args = opts.parse!(args)
end