Monday, August 16, 2010

Invoking Ruby Version Manager from Cron

In command prompt, you can usually invoke "rails runner" (the rails3 equlivalent of rails 2's "script/runner") by

cd /railsproject && bash -c "source /Users/Matt/.rvm/scripts/rvm && /usr/bin/env script/rails runner -e production 'FeedEntry.update_from_feed(\"http://www.website.com/feed.rss\")'"

but when to try to run it as a cron job, you will get

/railsproject/config/boot.rb:10:in `rescue in <top (required)>':
uninitialized constant Object::Bundler (NameError)
        from /railsproject/config/boot.rb:5:in `<top (required)>'
        from script/rails:5:in `require'

Inorder to solve this you need to
wrap your cron task in a bash login shell like this:

/bin/bash -l -c ' cd /railsproject && bash -c "source
/Users/Matt/.rvm/scripts/rvm && /usr/bin/env script/rails runner -e
production 'FeedEntry.update_from_feed(\"http://www.website.com/feed.rss\")'"