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.

This entry was published on August 23, 2008 under the following topics Linux

  • You could use Moment (– it lets you schedule http requests, which can be used to trigger server processes. It’s a different approach than traditional background jobs, but might make sense depending on your hosting setup.