Rails Rails 定时任务启动错误

76521 · 2015年12月22日 · 最后由 76521 回复于 2015年12月23日 · 3338 次阅读
rails运行环境是正常的但是启动定时任务时候报错定时任务我用的whenever我已经指定了ruby-2.2.2@rails444这个包了 为什么还会提示我检查这个包下的错误Checked in 'GEM_PATH=/home/vivo/.rvm/gems/ruby-1.9.3-p547:/home/vivo/.rvm/gems/ruby-1.9.3-p547@global', execute `gem env` for more information

这是我的定时任务
job_type :rake, "cd :path;PATH=#{ENV['PATH']} && :environment_variable=:environment bundle exec rake :task RAILS_ENV=development --silent :output "

set :output, File.expand_path("log/cron.log")

every :day, :at =>'4:00am' do
  rake 'elasticsearch:import'
end

log报错信息
Ignoring gem-wrappers-1.2.7 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.2.7
/home/vivo/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 15 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/home/vivo/.rvm/gems/ruby-1.9.3-p547:/home/vivo/.rvm/gems/ruby-1.9.3-p547@global', execute `gem env` for more information
    from /home/vivo/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
    from /home/vivo/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /home/vivo/.rvm/gems/ruby-2.2.2@rails444/bin/bundle:22:in `<main>'
    from /home/vivo/.rvm/gems/ruby-2.2.2@rails444/bin/ruby_executable_hooks:15:in `eval'
    from /home/vivo/.rvm/gems/ruby-2.2.2@rails444/bin/ruby_executable_hooks:15:in `<main>'

rake 是已经定义好的 job type

every :day, :at => '12:20am', :roles => [:app] do
  rake "app_server:task"
end

运行 gem env

#1 楼 @kikyous 默认的是 job type 是 production 模式,我想 development 模式起所以给重写了下,可以吧?

#2 楼 @qinfanpeng 运行了 看了看 环境没啥问题啊

RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.8
  - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/book/.rvm/gems/ruby-2.2.2@rails444
  - RUBY EXECUTABLE: /home/book/.rvm/rubies/ruby-2.2.2/bin/ruby
  - EXECUTABLE DIRECTORY: /home/book/.rvm/gems/ruby-2.2.2@rails444/bin
  - SPEC CACHE DIRECTORY: /home/book/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/book/.rvm/gems/ruby-2.2.2@rails444
     - /home/book/.rvm/gems/ruby-2.2.2@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://ruby.taobao.org/"]
  - REMOTE SOURCES:
     - https://ruby.taobao.org/
  - SHELL PATH:
     - /home/book/.rvm/gems/ruby-2.2.2@rails444/bin
     - /home/book/.rvm/gems/ruby-2.2.2@global/bin
     - /home/book/.rvm/rubies/ruby-2.2.2/bin
     - /home/book/.rvm/bin
     - /usr/local/jdk1.6.0_10/bin
     - /usr/local/jdk1.6.0_10/jre/bin
     - /usr/local/jdk1.6.0_10
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games

最近也折腾 whenever,遇到类似的坑,下面这个链接解决了问题 http://stackoverflow.com/questions/24092681/cron-whenever-not-working-with-rvm。另,官方 github 上面也有关于 rvm 的特别说明。

#5 楼 @glz1992 果真是这个问题,解决了,谢谢

需要 登录 后方可回复, 如果你还没有账号请 注册新账号