views:

627

answers:

3

I'm running a crontab that executes a rake task. I'm getting the following error (with MAILTO from crontab):

rake aborted!
no such file to load -- bundler
/Users/Mendel/Sites/misnooit/Rakefile:4
(See full trace by running task with --trace)

I'm using rvm with:
ruby: ruby 1.9.1p378
rails: Rails 3.0.0.beta
$GEM_HOME: /Users/Mendel/.rvm/gems/ruby-1.9.1-p378
bundler: bundler (0.9.11)

The error is pretty self explanatory but I'm not able to fix it.. Is there someone with more knowledge about this matter? Thanks in advance.

+1  A: 

Just guessing: is Ruby 1.9.1p378 your default Ruby?

I think it's not so you can just execute rvm --defaults "ruby-1.9.1-p378" If this doesn't help, are you sure bundler has been installed when ruby 1.9 was used?

Also, in your test/production environment, you may want to run you cron with another user than yourself. So I suggest you install rvm as "root", and set up (still as root) a default RVM that will be the default for all the system users. And of course, you can override this per user.

Cesario
A: 

I've had good experience using http://github.com/javan/whenever

It uses a Ruby DSL to manage cron tasks and it handles setting all the environment magic.

every 3.hours do
  runner "MyModel.some_process"
  rake "my:rake:task"
end
Daniel X Moore
A: 

have your run the command with --trace asserted to ensure there isn't something obvious in the rake command, but what you could do is chain the crontab commands

rvm 1.9.1;rake do_whatever_task

That way it will load the ruby environment every time prior to running rake.

naven87