Skip to content

Commit

Permalink
Adding identifier an as option and including sample monit file. Credi…
Browse files Browse the repository at this point in the history
…t to http://github.com/mguterl for the code.
  • Loading branch information
zmoazeni committed Apr 9, 2010
1 parent bd8c4ae commit 82809a0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
23 changes: 23 additions & 0 deletions contrib/delayed_job_multiple.monitrc
@@ -0,0 +1,23 @@
# an example Monit configuration file for delayed_job running multiple processes
#
# To use:
# 1. copy to /var/www/apps/{app_name}/shared/delayed_job.monitrc
# 2. replace {app_name} as appropriate
# 3. add this to your /etc/monit/monitrc
#
# include /var/www/apps/{app_name}/shared/delayed_job.monitrc

check process delayed_job_0
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.0.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 0"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 0"

check process delayed_job_1
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.1.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 1"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 1"

check process delayed_job_2
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.2.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 2"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 2"
22 changes: 18 additions & 4 deletions lib/delayed/command.rb
Expand Up @@ -37,6 +37,9 @@ def initialize(args)
opts.on('--pid-dir=DIR', 'Specifies an alternate directory in which to store the process ids.') do |dir| opts.on('--pid-dir=DIR', 'Specifies an alternate directory in which to store the process ids.') do |dir|
@options[:pid_dir] = dir @options[:pid_dir] = dir
end end
opts.on('-i', '--identifier=n', 'A numeric identifier for the worker.') do |n|
@options[:identifier] = n
end
end end
@args = opts.parse!(args) @args = opts.parse!(args)
end end
Expand All @@ -51,14 +54,25 @@ def daemonize
dir = @options[:pid_dir] dir = @options[:pid_dir]
Dir.mkdir(dir) unless File.exists?(dir) Dir.mkdir(dir) unless File.exists?(dir)


worker_count.times do |worker_index| if @worker_count > 1 && @options[:identifier]
process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}" raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :ARGV => @args) do |*args| elsif @worker_count == 1 && @options[:identifier]
run process_name 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 end
end end


def run_process(process_name, dir)
Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :ARGV => @args) do |*args|
run process_name
end
end

def run(worker_name = nil) def run(worker_name = nil)
Dir.chdir(RAILS_ROOT) Dir.chdir(RAILS_ROOT)


Expand Down

0 comments on commit 82809a0

Please sign in to comment.