Rake task scheduling

I am developing a Rails application.

If I have some rake tasks in lib / tasks , how do I implement a function to tell my application to run certain rake tasks at 00:00:00 every day (i.e. do certain tasks every day at midnight)?

+4
source share
2 answers

I suggest you use whenever

+7
source

I would set rake tasks as concrete cron jobs in crontab. I used this method to automate archiving of old data. It is convenient that you can receive an e-mail with an exit from a rake.

Crontab example:

MAILTO=" me@domain.ext " 0 0 * * * /path/to/archive_script.sh 

Sample script:

 #!/bin/bash source /home/user/.bashrc cd /path/to/project export RAILS_ENV=production bundle exec rake archive_old_items -s 
+2
source

All Articles