开发者

Rake task which executes other rake tasks via system fails -- no such file to load 'rake'

开发者 https://www.devze.com 2023-01-25 08:36 出处:网络
I\'ve written a rake task to run a few other rake tasks via system (so as to bind ActiveRecord to different databases, among other things). It works fine on my OS X box, but fails on our production Li

I've written a rake task to run a few other rake tasks via system (so as to bind ActiveRecord to different databases, among other things). It works fine on my OS X box, but fails on our production Linux boxes with a load error. The tas开发者_运维技巧ks trivially boil down to:

namespace :jobs do

  task :foo => :environment do
    system "rake jobs:bar"
  end

  task :bar => :environment do
    puts "foobar"
  end

and the traced output is:

-bash-3.2$ rake jobs:foo --trace
(in /the/path)
** Invoke jobs:foo (first_time)
** Invoke environment (first_time)
** Execute environment
** Erubis 2.6.6
** Execute jobs:foo
/usr/bin/rake:19:in `load': no such file to load -- rake (LoadError)
    from /usr/bin/rake:19

I dumped a puts $: into /usr/bin/rake and have discovered something interesting. The primary job has a load path containing both of these paths:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

while the secondary job has a load path containing only:

/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib

which probably explains the load error, but not the reason for it. Any ideas?


Check to make sure your install has set up the required environment variables correctly. http://docs.rubygems.org/read/chapter/3 The same problem occurred for me when using "export RUBYOPT=RUBYGEM" instead of "export RUBYOPT=RUBYGEMS". Ahh the difference a single character can make.


If you are really trying to invoke a rake task from another rake task. Why not do this? "Rake::Task['jobs:bar'].invoke". You can even do it in a loop, for instance an Array#each that changes ENV vars, etc. I've done this in tasks before.

Though, if your example was contrived and your not really calling one task but just asking why the sub shell has different PATH setting, that I do not know. Perhaps if it's hard, then it's a hint that it should be done another way.

0

精彩评论

暂无评论...
验证码 换一张
取 消