How to Schedule a Ruby on Rails Rake Task Via Cron

If you ever want to run a Rails Rake task on a schedule via cron, here is the entry you need to make in crontab:

*/5 * * * * cd /var/www/apps/rails_app/ && /usr/local/bin/rake RAILS_ENV=production rake_task:goes_here

The above snippet will run the given Rails Rake task using the production environment every 5 minutes. Note that you need to first change the directory path to your rails app and then call the rake task. This may all be common knowledge but it was new to me.

Leave a comment