gpt4 book ai didi

ruby-on-rails - 从 crontab 运行 rake 任务

转载 作者:行者123 更新时间:2023-12-04 05:44:51 26 4
gpt4 key购买 nike

我使用 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

怎么了?

最佳答案

我对 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

关于ruby-on-rails - 从 crontab 运行 rake 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3871312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com