Julian wrote: > hi there, > > i have written a middleware-class wich is doing what a cronjob should > do. it is doing some backup-stuff, and repeats that every 12 hours. it > is a thread and is placed in the list of middleware-classes, but not > processing any request or overwriting any typical method for a > middleware class. > > my problem is: with the devlopment-server it's created once. with > mod_python and _three_ apache instances, there are three instances of > my backup-thread, but i want to have only one. > > how can i start a thread (without having an extra cronjob) in my > django-app only once on the whole server??? the hackish solution would > be to store the actual PID on a special place. > Doing a cronjob's job in a middleware-spawned thread is hackish to begin with-- storing a PID is the best way to do what you want done given your constraints.
Another implementation you might consider, is to create a view that executes the backup job when called. Do a check when it is called to see if it's been at least twelve hours. Set up a cronjob on your local machine that uses curl or wget to make a request that executes the backup job. The check to see if its been at least twelve hours would prevent the job from being abused if someone finds it. If you want to hide it, make a view that starts the backup job, and then raises a 404-- the code will still get through, but anyone that visits the URL would have no way of knowing that it was doing something. If a cronjob is really what fits the bill, consider switching your hosting provider or plan to something that includes cronjobs-- its worth it to not be hackish. :) Jeff Anderson
signature.asc
Description: OpenPGP digital signature

