English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app

Use a Cron Job to Automate Sphinx Index Refresh from Rails Rake Task


If using Sphinx, you need to refresh indexes when you add new content to your database. This is fairly easy to do by hand

rake thinking_sphinx:index RAILS_ENV=production
But if you want to automate this and use a cron, remember to set the PATH, SHELL and RAILS_ENV variables for your job. The environment isn't the same when you're doing it by hand and your index will fail silently :(

You find your specific PATH and SHELL info like so

echo $PATH
echo $SHELL
To get into the cron and set your schedule

crontab -e


# re-index production sphinx every 15 minutes
*/15 * * * * root cd /var/www/rails_app && /usr/local/bin/rake thinking_sphinx:index >> /dev/null 2>&1

More information available here http://heimdull.blogspot.com/2009/05/journey-with-thinking-sphinx-and-crond.html http://groups.google.com/group/thinking-sphinx/browse_thread/thread/5451458fae7d6124

Tagged w/ #cron #rakeruby on rails