Django scheduled jobs

陌路散爱 提交于 2019-12-21 23:12:52

问题


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.


回答1:


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_notices.py

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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1534268/django-scheduled-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!