views:

190

answers:

2
+1  Q: 

Cronjobs in Django

I'm writing a database application where certain parts of the database might need updates based on time, not based upon user actions.

For example, there may be certain values that are updated daily, and certain other values that must be updated say, four hours after the database entry is created.

Thus I need some way to update values regularly (a script that updates the database daily) and a way to update values at a specific time in the future (when the entry is created, you need to run an update in four hours).

The database will be managed through a web front end, so I'm using Django to set up the database and the administration, because Django makes designing the database a pleasure. However, I have no idea how to set up the other side, the side that updates the database at certain times.

How would you guys suggest doing this? Would it be sufficient to run a python script and run it with a daily cronjob, or is that not the best practice? Is this sort of thing done frequently, and do tools / methods exist to do this?

I have no experience with this sort of thing, and I'd like to know how it's generally done before I jump in and start reinventing the wheel.

+3  A: 

http://code.google.com/p/django-cron/ :)

FractalizeR
+5  A: 

You can set a management task (one that's called with ./manage.py <task name>) that does what you need. This way you got access to all the settings, models and stuff that you use in your project. And it's also easy to maintain such a script.

kender
If you have access to put scripts in a cronjob I prefer doing it this way. Creating management tasks is the Django way to do it. You also get the added benefit of being able to manually run the commands from the commandline.
Andre Miller
Absolutely. It is very easy to do:http://docs.djangoproject.com/en/dev/howto/custom-management-commands/
DrBloodmoney