Reputation: 38842
I am developing a Rails application.
If I have some rake tasks under lib/tasks, how to implement the feature to specify my app to run certain rake tasks at 00:00:00 every day (that is, run certain tasks every day at midnight)?
Upvotes: 5
Views: 8001
Reputation: 2413
I would setup the rake tasks as specific cron jobs in crontab. I've used this method to automate archival of older data. It's handy that you can get an email with the output from rake as well.
Example crontab:
MAILTO="[email protected]"
0 0 * * * /path/to/archive_script.sh
Example script:
#!/bin/bash
source /home/user/.bashrc
cd /path/to/project
export RAILS_ENV=production
bundle exec rake archive_old_items -s
Upvotes: 2