forked from saurabh/orbit4-5
36 lines
1.3 KiB
Ruby
36 lines
1.3 KiB
Ruby
|
namespace :orbit_cron do
|
||
|
task :install => :environment do
|
||
|
|
||
|
# Setup environment in crontab
|
||
|
cron_env ="#!/bin/bash\n"+
|
||
|
"PATH=#{ENV['PATH']}\n"+
|
||
|
"RUBYLIB=#{ENV['RUBYLIB']}\n"+
|
||
|
"GEM_HOME=#{ENV['GEM_HOME']}\n"+
|
||
|
"GEM_PATH=#{ENV['GEM_PATH']}\n"+
|
||
|
"RUBYOPT=#{ENV['RUBYOPT']}\n\n"
|
||
|
|
||
|
# Email cron job
|
||
|
email_cron = "* * * * * cd #{Rails.root.to_s} && bundle exec rake email:deliver_all > /dev/null\n"
|
||
|
|
||
|
File.open('lib/tasks/orbit_cron', "w+") do |f|
|
||
|
f.write(cron_env + email_cron)
|
||
|
end
|
||
|
|
||
|
# Check if current crontab is empty
|
||
|
if %x(crontab -l).eql? ""
|
||
|
%x(crontab #{Rails.root.to_s+'/lib/tasks/orbit_cron'})
|
||
|
%x(rm #{Rails.root.to_s+'/lib/tasks/orbit_cron'})
|
||
|
puts "\n"
|
||
|
puts "Orbit cron jobs installed\n"
|
||
|
else
|
||
|
puts "\n"
|
||
|
puts "============================ Warning! ============================\n"
|
||
|
puts "Crontab is not empty!\n"
|
||
|
puts "Please edit crontab with command 'crontab -e' and paste the following lines:\n"
|
||
|
puts "=================================================================\n"
|
||
|
puts cron_env + email_cron
|
||
|
puts "=================================================================\n"
|
||
|
puts "\n\n"
|
||
|
end
|
||
|
end
|
||
|
end
|