Tuesday, July 8, 2008

rake, cron, ruby, and scheduling tasks

This post is how to setup a cron job, on *nix server using rake. Why use rake ? well rake allows you access to all your models within your application. So writing a task is like writing any other function, and all that DRY goodness without having to rewrite a thing. A very good write up on Rake here : Rake Tutorial.
Setting up a cron job is simple, here is a write up in the Ubuntu documentation - Cron How To.

So just create a directory in your home, or anywhere , to where you will be placing your shell scripts, and/or logs. You could call rake directly in the crontab, but I prefer to keep it in a script, the more complex it gets later, will be easier to change.

its simple after that
cd / && /usr/bin/rake RAILS_ENV=production raketask1 raketask2

and yes you can chain rake tasks and they will run in that order. Very cool stuff. Another good write up where I found out about chaining - Rake Around the Rosie

No comments: