无论什么时候运行cron都无法找到gem bundler?

时间:2018-01-21 06:27:46

标签: ruby-on-rails ruby cron rvm whenever

我正在使用gem来编写一个简单的cron作业。

every 1.minute do 
  runner "ValidModel.clean"
end

我看到这个cron在正确的时间触发但rails命令ValidModel.clean没有成功。它给出以下错误。

/home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
        from /home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in `activate_bin_path'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/bundle:23:in `<main>'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `eval'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `<main>'

我正在使用RVM。此问题是否与使用RVM时有关?我感谢任何帮助!

更新

在gemfile中我放了

gem 'whenever', require: false

当我运行crontab -l时,它会列出以下内容

PATH=/home/deploy/apps/app/shared/bundle/ruby/2.4.0/bin:/home/deploy/.rvm/gems/ruby-2.4.2/bin:/home/deploy/.rvm/gems/ruby-2.4.2@global/bin:/home/deploy/.rvm/rubies/ruby-2.4.2/bin:/home/deploy/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=""

* * * * * /bin/bash -l -c 'cd /home/deploy/apps/app/releases/20180121061036 && bundle exec bin/rails runner -e production '\''ValidModel.clean'\'' >> /home/deploy/apps/app/releases/20180121061036/log/cron.log 2>&1'

我感谢任何见解!非常感谢!

0 个答案:

没有答案