我遵循了这个问题https://github.com/javan/whenever/issues/714
并像我这样设置我的schedule.rb
。
env :PATH, ENV['PATH']
set :output, {:error => '~/Desktop/z.error.log', :standard => '~/Desktop/z.standard.log'}
every 1.minute do
runner 'Price.create'
end
然后我检查了我的crontab -l
,它显示了以下命令
PATH=/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3@global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/bin:/usr/local/opt/mysql@5.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
* * * * * /bin/bash -l -c 'cd /Users/MyUserName/Desktop/my-project && bundle exec bin/rails runner -e production '\''Price.create'\'' >> ~/Desktop/z.standard.log 2>> ~/Desktop/z.error.log'
# End Whenever generated tasks for: /Users/MyUserName/Desktop/my-project/config/schedule.rb at: 2018-01-30 02:13:32 +0800
它似乎很棒且可执行,但是,我检查了错误日志并发现了以下错误。
bundler:无法加载命令:bin / rails(bin / rails)
Bundler::GemNotFound: Could not find erubi-1.7.0 in any of the sources
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `map!'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `materialize'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:170:in `specs'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:237:in `specs_for'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:226:in `requested_specs'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/runtime.rb:108:in `block in definition_method'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/runtime.rb:20:in `setup'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler.rb:107:in `setup'
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/setup.rb:20:in `<top (required)>'
/Users/MyUserName/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/MyUserName/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
我感到有点困惑,并想知道为什么我无法加载正确的宝石路径。
环境:
OSX:10.13.2
Rails 5.1.4
Ruby 2.3.3
我发现日志中的错误消息表明
/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize'`,
但是,我检查了我的crontab -l
,它清楚地显示了此设置
#sm start rvm
PATH="/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3@global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3@global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/bin:/usr/local/opt/mysql@5.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin"
GEM_HOME='/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails514'
GEM_PATH='/Users/MyUserName/.rvm/gems/ruby-2.3.3@rails514:/Users/MyUserName/.rvm/gems/ruby-2.3.3@global'
MY_RUBY_HOME='/Users/MyUserName/.rvm/rubies/ruby-2.3.3'
IRBRC='/Users/MyUserName/.rvm/rubies/ruby-2.3.3/.irbrc'
RUBY_VERSION='ruby-2.3.3'
#sm end rvm
我很困惑为什么它仍然得到错误的rvm版本。 我错过了什么吗?
我更改了默认gemset
后,效果非常好。
我使用了这个命令
rvm use 2.3.3@rails514 --default
但有人能告诉我如何在crontab
中设置正确的路径,而不是设置rvm默认路径吗?
答案 0 :(得分:1)
尝试运行
rvm cron setup
不确定是否能解决问题,但有一次类似的问题,并为我工作。祝你好运!