views:

474

answers:

3

I'm writing some auction functionality for a website powered by Django, and there is an option to have the auction be extended by a few seconds every time somebody bids (so that there is no last-minute sniping). When the auction is finished, certain things need to be done like notifying the winner of their victory and notifying the seller to whom they need to send the item.

How, in Django, do I go about running an auction-completion script whenever an auction ends, especially when the auction end time may be a moving target?

Thanks.

+2  A: 

Sounds like you probably want to have whatever code is responsible for closing the auction fire a custom signal to indicate that it's happening.

James Bennett
Yeah, except that my problem is finding when to run the code responsible for closing the auction.
Nate
+2  A: 

It sounds like extending an auction_end DateTime field could easily be done on the bid() view

As far as emailing outcomes you should write a management script http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ checking for auctions that have ended and haven't had notifications sent and schedule this script to run in cron at regular intervals (by minute if neccessary). An example would be pinax's django-notification emit_notices script.

http://github.com/jtauber/django-notification/blob/master/notification/management/commands/emit%5Fnotices.py

Better still you might be able to leverege django-notification itself.

michael
+1  A: 

Django command extensions provides jobs system (job scheduling). After you add it to the crontab it is capable of running jobs hourly/daily/weekly/monthly.

I think that it should be easy to extend job management command to acomplish your tasks.

sorki