2011-09-09 33 views
0

cron作业在rails 3中无法正常工作。我每当使用gem时都使用下面是我正在使用的代码。cron作业在生产模式下不能在rails上运行ruby

schedule.rb文件

every 1.hours do 
    command "cd /home/me/my_app/current" 
    rake "thinking_sphinx:index RAILS_ENV=production" 
end 

every 1.day, :at => '12.01 am' do 
    command "cd /home/me/my_app/current" 
    rake "messages_counter_for_user_and_group RAILS_ENV=production" 
    command "cd /home/me/my_app/current" 
    runner "RAILS_ENV=production User.update_all(:daily_message_count => 0)" 
end 

从Capistrano的部署脚本: -

task :long do 
transaction do 
    cron_tab_activate 
end 

task:cron_tab_activate, :roles=>:app do 
send(run_method, "cd #{current_path} && RAILS_ENV=#{stage} whenever --update-crontab test ") 
end 

我使用RVM。 Ruby 1.9.2,Rails 3.0.10

回答

0

而不是使用自定义capistrano任务,我会建议加载每当宝石提供的capistrano任务。

添加到deploy.rb

require 'whenever/capistrano'