Hi, i’ve a little problem. i’ve to run a method every 5 minutes with
cron, but i don’t know what and where i’ve to write it. The method is
written, but to run it ? i know that i’ve to use the script/runner (does
it take a lot of resources? does exist something better?), but to run it
every 5 minutes?
5 * * * script/runner -e production “Class.method” ?
and in which file should i put it ? (i’m under gentoo with vixie-cron)
Thanks
Why create an external script?
I prefer an external script so that I can add some documentation if
necessary for whomever else might come across this crontab. Also, it
allows me to test the script and run it manually when necessary.
We often have special rake tasks and shell scripts that go along with
our rails applications, and we maintain them in subversion, so, this
allows us to modify them within svn without needing to re-edit our
crontab each time there is a change.
I prefer an external script so that I can add some documentation if
necessary for whomever else might come across this crontab. Also, it
allows me to test the script and run it manually when necessary.
We often have special rake tasks and shell scripts that go along with
our rails applications, and we maintain them in subversion, so, this
allows us to modify them within svn without needing to re-edit our
crontab each time there is a change.
Most cron implementations also support this format
*/5 * * * * /path/to/script
Beware that the full rails stack has gotten quite large and loading
and unloading it from cron can be painful. If you don’t need all of
rails (for ex. ActionPack), just load what you need. Here’s a quick
script that loads active record and all the models in a rails project.
It hasn’t been tested, but should get you most of the way there.