Permalink
Browse files

Adding identifier an as option and including sample monit file. Credi…

…t to http://github.com/mguterl for the code.
  • Loading branch information...
1 parent bd8c4ae commit 82809a0fd6dabdcf14e525e89357e9eac9513e5f @zmoazeni zmoazeni committed Apr 9, 2010
Showing with 41 additions and 4 deletions.
  1. +23 −0 contrib/delayed_job_multiple.monitrc
  2. +18 −4 lib/delayed/command.rb
View
23 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"
View
22 lib/delayed/command.rb
@@ -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|
@options[:pid_dir] = dir
end
+ opts.on('-i', '--identifier=n', 'A numeric identifier for the worker.') do |n|
+ @options[:identifier] = n
+ end
end
@args = opts.parse!(args)
end
@@ -51,14 +54,25 @@ def daemonize
dir = @options[:pid_dir]
Dir.mkdir(dir) unless File.exists?(dir)
- worker_count.times do |worker_index|
- process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
- Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :ARGV => @args) do |*args|
- run process_name
+ 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
+ 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)
Dir.chdir(RAILS_ROOT)

0 comments on commit 82809a0

Please sign in to comment.