从crontab运行rake任务

时间:2010-10-06 09:53:51

标签: ruby-on-rails

我使用Ubuntu,我尝试从cron运行我的rake任务 我的佣金任务:

namespase :import do
   task :import_twitter => :environment do
      puts "Twitter importing...." 
   end
end

schedule.rb文件

every 1.minutes do
  rake "import:import_twitter", :output => {:error => 'error.log', :standard => 'cron.log'}
end

随时生成crontab任务

 # Begin Whenever generated tasks for: /home/administrator/www/my_application/config/schedule.rb
    PATH=/usr/local/rvm/gems/ruby-1.9.2-p0/bin:/bin:/usr/local/rvm/rubies/ruby-1.9.2-p0/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    * * * * * cd /home/administrator/www/my_application && RAILS_ENV=production /usr/bin/env rake import:import_twitter >> cron.log 2>> error.log


# End Whenever generated tasks for: /home/administrator/www/my_application/config/schedule.rb

在crontab error.log中我有

/usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:340:in `bin_path': can't find executable rake for rake-0.8.7 (Gem::Exception)
    from /usr/local/rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'

但是,当我从控制台运行此任务时,它可以正常工作

path_to_my_project >rake  import:import_twitter

怎么了?

1 个答案:

答案 0 :(得分:4)

我和rvm有同样的问题。如果我想要它的工作,我定义HOME VARIABLE并注释PATH变量,它是有效的。

我认为加载你的环境是一个rvm问题。

# Begin Whenever generated tasks for: supermarmite
SHELL=/bin/bash
HOME=/var/rails/supermarmite
#PATH=/var/rails/supermarmite/.rvm/gems/ruby-1.9.2-p0/bin:/var/rails/supermarmite/.rvm/gems/ruby-1.9.2-p0@global/bin:/var/rails/supermarmite/.rvm/rubies/ruby-1.9.2-p0/bin:/var/rails/supermarmite/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/mongodb/bin

0 * * * * source ~/.bashrc && cd /var/rails/supermarmite/site/releases/20100930044915 && RAILS_ENV=production rake -s evaluate_notify

# End Whenever generated tasks for: supermarmite