views:

30

answers:

2

I have a Django application.

One of my models looks like this:

class MyModel(models.Model):

    def house_cleaning(self):
    // cleaning up data of the model instance

Every time when I update an instance of MyModel, I'd need to clean up the data N days later. So I'd like to schedule a job to call

this_instance.house_cleaning() 

N days from now.

Is there any job queue that would allow me to:

  • Integrate well with Django - allow me to call a method of individual model instances
  • Only run jobs that are scheduled to run today
  • Ideally handle failures gracefully

Thanks

+1  A: 

Is there any reason why a cron job wouldn't work? Or something like django-cron that behaves the same way? It's pretty easy to write stand-alone Django scripts. If you want to trigger house cleaning on some change to you model after a certain number of days, why not create a date flag in the model which is set to N days in the future when the job needs to be scheduled? You could run a script on a daily basis which pulls all records where the date is <= today, calls the instance's house_cleaning() method and then clears the date field. If an exception is raised during the process, it's easy enough to log it or dispatch an email.

mazelife
+2  A: 

django-chronograph might be good for your use case. If you write your cleanup jobs as django commands, then you schedule them to run at some time. It runs using unix cron behind the scene.

ars