Class: Delayed::Command
- Inherits:
-
Object
- Object
- Delayed::Command
- Defined in:
- lib/vendor/plugins/delayed_job/lib/delayed/command.rb
Instance Attribute Summary collapse
-
#worker_count ⇒ Object
Returns the value of attribute worker_count.
Instance Method Summary collapse
- #daemonize ⇒ Object
-
#initialize(args) ⇒ Command
constructor
A new instance of Command.
- #run(worker_name = nil) ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
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 |
# File 'lib/vendor/plugins/delayed_job/lib/delayed/command.rb', line 9 def initialize(args) @options = {:quiet => true} @worker_count = 1 opts = OptionParser.new do |opts| opts. = "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| ENV['RAILS_ENV'] = e 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 end @args = opts.parse!(args) end |
Instance Attribute Details
#worker_count ⇒ Object
Returns the value of attribute worker_count.
7 8 9 |
# File 'lib/vendor/plugins/delayed_job/lib/delayed/command.rb', line 7 def worker_count @worker_count end |
Instance Method Details
#daemonize ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/vendor/plugins/delayed_job/lib/delayed/command.rb', line 36 def daemonize worker_count.times do |worker_index| process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}" Daemons.run_proc(process_name, :dir => "#{RAILS_ROOT}/tmp/pids", :dir_mode => :normal, :ARGV => @args) do |*args| run process_name end end end |
#run(worker_name = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vendor/plugins/delayed_job/lib/delayed/command.rb', line 45 def run(worker_name = nil) Dir.chdir(RAILS_ROOT) # Replace the default logger…too bad Rails doesn't make this easier Rails.logger.instance_eval do @log.reopen File.join(RAILS_ROOT, 'log', 'delayed_job.log') end Delayed::Worker.logger = Rails.logger ActiveRecord::Base.connection.reconnect! Delayed::Job.worker_name = "#{worker_name} #{Delayed::Job.worker_name}" Delayed::Worker.new(@options).start rescue => e logger.fatal e STDERR.puts e. exit 1 end |