Cron 作业错误帮助 - Rails Runner 错误
* * * * * /bin/bash -l -c 'cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"'
基本上我需要执行以下操作:
- 使用以下命令加载 Ruby RVM
- 导航到
MyApp
Dir - 运行以下行:
rails runner "Resque.enqueue(Place)
上面的 cron 似乎正在运行,但它生成以下内容rails runner 出现错误 这是怎么回事?
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `new'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `search'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:354:in `gems_size'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:179:in `resolve'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/source_index.rb:95:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `each'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:160:in `start'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:128:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `catch'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:151:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:90:in `specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:135:in `specs_for'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:124:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:11:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:107:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/setup.rb:6
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/boris/projects/chaggregator/config/boot.rb:6
from script/rails:5:in `require'
from script/rails:5
* * * * * /bin/bash -l -c 'cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"'
Basically I need to do the following:
- Load Ruby with RVM
- Navigate to
MyApp
Dir - Run the following line:
rails runner "Resque.enqueue(Place)
The above cron seems to be running, but its producing the following errors with rails runner
whats going on?
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `new'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `search'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:354:in `gems_size'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:179:in `resolve'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/source_index.rb:95:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `each'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:160:in `start'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:128:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `catch'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:151:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:90:in `specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:135:in `specs_for'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:124:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:11:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:107:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/setup.rb:6
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/boris/projects/chaggregator/config/boot.rb:6
from script/rails:5:in `require'
from script/rails:5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,最好的方法是使用 rvm 包装器。您可以创建这样的包装器:
二进制文件可以是rails、rake、gem 或您安装的任何其他ruby 二进制文件。发生的情况是 rvm 创建一个包装器,该包装器将在执行rails 命令之前获取正确的 rvm 环境。在系统范围的 rvm 上,包装器通常会放置在 /usr/local/rvm/bin/ 中。
现在,您可以从 cron 执行以下操作:
这将 cd 进入您的应用程序目录,并每 3 分钟执行一次您刚刚创建的 rvm 包装器。本示例基于rails 3和生产环境。
Actually the best way to do this is to use rvm wrapper. You can create a wrapper like this:
binary can be rails, rake, gem or whatever other ruby binary you have installed. What happens is that rvm creates a wrapper that will source the correct rvm environment before executing the rails command. On system wide rvm, the wrapper will normally be placed in /usr/local/rvm/bin/
Now from cron you can just do:
This will cd into your app directory and execute the rvm wrapper you just created every 3 minutes. This example is based on rails 3 and production environment.
在运行任何 Ruby 代码之前,您需要通过 RVM 获取正确的环境。因此,在命令中包含类似这样的内容:
因此,一个潜在的解决方案是:
You need to source the right environment via RVM before any Ruby code runs. So include something like this in the command:
So a potential solution would be:
这里有很多令人感动的内容,这里有一些关于在您的环境中检查的事情的指示(ruby、rvm、bundle)——发布您的发现并从那里开始。
捆绑程序的路径问题,更改还是不更改?
捆绑错误
我猜这些命令在外部运行良好克朗?如果您以其他用户身份运行 cron 作业,请检查该用户的环境。
Lots of moving pieces here, here are a couple of pointers on things to check in your environment (ruby, rvm, bundle) - post your findings and will go from there.
Path's issue with bundler, to change or not to change?
Bundle bug
I guess the commands runs fine outside of cron? if you're running your cron job as a different user, check the environment of that user.