lib/capistrano/delayed_job/helpers.rb in capistrano-delayed-job-1.0.1 vs lib/capistrano/delayed_job/helpers.rb in capistrano-delayed-job-1.1.0
- old
+ new
@@ -2,14 +2,20 @@
module Capistrano
module DelayedJob
module Helpers
- def bundle_delayed_job(*args)
- bin_dir = %w{bin script}.find{|dir_name| Dir.exists?(dir_name)}
- raise "No bin or script dir found in project" if bin_dir.nil?
- SSHKit::Command.new(:bundle, :exec, "#{bin_dir}/delayed_job", args).to_command
+ def delayed_job_command(*args)
+ "cd #{current_path} && " <<
+ SSHKit::Command.new("HOME=/home/#{deploy_user}",
+ "RAILS_ENV=#{fetch(:rails_env)}",
+ :nice,
+ '-n 15',
+ :bundle,
+ :exec,
+ delayed_job_script_relative_path,
+ args).to_command
end
def dj_template(template_name)
config_file = "#{fetch(:templates_path)}/#{template_name}"
# if no customized file, proceed with default
@@ -22,19 +28,29 @@
def file_exists?(path)
test "[ -e #{path} ]"
end
def deploy_user
- capture :id, '-un'
+ @deploy_user ||= capture(:id, '-un')
end
def sudo_upload!(from, to)
filename = File.basename(to)
to_dir = File.dirname(to)
tmp_file = "#{fetch(:tmp_dir)}/#{filename}"
upload! from, tmp_file
sudo :mv, tmp_file, to_dir
end
+ def delayed_job_script_relative_path
+ "#{relative_bin_path}/delayed_job"
+ end
+
+ private
+ def relative_bin_path
+ bin_path = %w{bin script}.find { |dir_name| Dir.exists?(dir_name) }
+ raise "No bin or script dir found in project" if bin_path.nil?
+ bin_path
+ end
end
end
end