I need to do some database housekeeping periodically. Right now I have
a method in my model, which I am calling from ./script/console like x
= Model.update_all and it works fine.
I need to put this in cron. I know that I should be using
./script/runner, I have looked a lot for an example script
encapsulating my method to do this. But could not find any. It would
be great if some one can post a simple script that I can call from
cron.
I am also not sure if ./script/runner calls methods in my controller or model.
script/runner will run model methods like this script/runner -e
production 'Emailer.send_daily_announcements'
Be aware that script/runner loads the Rails framework every time it
runs, so it starts slow. I.E. don't use it for jobs that you run all the
time.
For a database monitoring daemon that runs a simple query every 5
seconds, I use a daemon that starts with './script/runner .... &' and
runs constantly - the method that I call has an infinite loop. This way
the environment only loads once.