Class Delayed::Command
In: lib/delayed/command.rb
Parent: Object

Methods

daemonize   new   run  

Attributes

worker_count  [RW] 

Public Class methods

[Source]

    # File lib/delayed/command.rb, line 9
 9:     def initialize(args)
10:       @files_to_reopen = []
11:       @options = {:quiet => true}
12:       
13:       @worker_count = 1
14:       
15:       opts = OptionParser.new do |opts|
16:         opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run"
17: 
18:         opts.on('-h', '--help', 'Show this message') do
19:           puts opts
20:           exit 1
21:         end
22:         opts.on('-e', '--environment=NAME', 'Specifies the environment to run this delayed jobs under (test/development/production).') do |e|
23:           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"
24:         end
25:         opts.on('--min-priority N', 'Minimum priority of jobs to run.') do |n|
26:           @options[:min_priority] = n
27:         end
28:         opts.on('--max-priority N', 'Maximum priority of jobs to run.') do |n|
29:           @options[:max_priority] = n
30:         end
31:         opts.on('-n', '--number_of_workers=workers', "Number of unique workers to spawn") do |worker_count|
32:           @worker_count = worker_count.to_i rescue 1
33:         end
34:       end
35:       @args = opts.parse!(args)
36:     end

Public Instance methods

[Source]

    # File lib/delayed/command.rb, line 38
38:     def daemonize
39:       ObjectSpace.each_object(File) do |file|
40:         @files_to_reopen << file unless file.closed?
41:       end
42:       
43:       worker_count.times do |worker_index|
44:         process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
45:         Daemons.run_proc(process_name, :dir => "#{RAILS_ROOT}/tmp/pids", :dir_mode => :normal, :ARGV => @args) do |*args|
46:           run process_name
47:         end
48:       end
49:     end

[Source]

    # File lib/delayed/command.rb, line 51
51:     def run(worker_name = nil)
52:       Dir.chdir(RAILS_ROOT)
53:       
54:       # Re-open file handles
55:       @files_to_reopen.each do |file|
56:         begin
57:           file.reopen File.join(RAILS_ROOT, 'log', 'delayed_job.log'), 'w+'
58:           file.sync = true
59:         rescue ::Exception
60:         end
61:       end
62:       
63:       Delayed::Worker.logger = Rails.logger
64:       ActiveRecord::Base.connection.reconnect!
65:       
66:       Delayed::Job.worker_name = "#{worker_name} #{Delayed::Job.worker_name}"
67:       
68:       Delayed::Worker.new(@options).start  
69:     rescue => e
70:       Rails.logger.fatal e
71:       STDERR.puts e.message
72:       exit 1
73:     end

[Validate]