Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling Rake tasks

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)?

like image 808
Mellon Avatar asked Dec 28 '22 12:12

Mellon


2 Answers

I suggest that you use whenever

like image 102
p.matsinopoulos Avatar answered Jan 06 '23 23:01

p.matsinopoulos


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
like image 23
Nick Avatar answered Jan 07 '23 00:01

Nick