Background processing in rails
This may seem like a frequently asked question on stackoverflow, but my requirements are slightly different. While I have previously used BackgroundRB and DJ to run background processes in ruby, this time my requirement is to run some heavy analytic and math calculations on a huge dataset and I only need to do this in the first 15 days of the month.Walking this I am tempted to use cron and run a ruby script to accomplish this.
What I would like to know / understand: 1 - Uses cron - a good idea (because I am not a sysadmin and so when I have the basic idea of cron I am not too sure about doing it perfectly) 2 - Can we we somehow modify the DJ to start only in the first 15 days of the month (using / without using cron) and then just stop and exit once all the jobs in the queue for the day have finished (don't want this every time ping DB for a new one assignments ... no matter what assignments are in the queue when the DJ starts it will be all).
I'm not sure if I put the question correctly, but any help in this direction would be much appreciated.
thanks
source to share
Yeah why not? Go with cron. It's really well tested in the wild, well suited for intermittent tasks, and incredibly easy to use. You don't even need to learn the crontab syntax (although it's very easy) - just drop your script in /etc/cron.daily (this option may only be available on some Linux distributions).
I'm not sure about "only the first days of the month", but you can easily deal with this condition within your task, right?
EDIT:
Check the paired answer to see how to run the task only for a specific range of days.
source to share
I also had this requirement. I followed Recipe 75 "Automatic Periodic Tasks" in the Advanced Rails Recipes book . The recipe was written by David Bock. It has some code snippets and guidelines on how this can be achieved using cron and capistrano. However, there is an unresolved (but mentioned) issue regarding the users / permissions that should be on the target machine. It's not very hard to get it right, you just have to remember to do it and put it in your capistrano deployment script.
It seems that David Bock kept working on this and now he has created a gem to use with cron: see his blog and follow crondonkulous on github . Crondonkulous can take very good care of this user / permission and more, I haven't tried it.
Jarl
source to share