Mellon
Mellon

Reputation: 38842

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

Upvotes: 5

Views: 8001

Answers (2)

Nick
Nick

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

p.matsinopoulos
p.matsinopoulos

Reputation: 7810

I suggest that you use whenever

Upvotes: 8

Related Questions