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)?
I suggest that you use whenever
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With