Django定期工作 [英] Django scheduled jobs

查看:123
本文介绍了Django定期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个由Django提供支持的网站编写一些拍卖功能,而且每次有人出价时都可以将拍卖延长几秒钟(这样就没有最后一刻的狙击)。拍卖结束时,需要做某些事情,例如通知赢家的胜利,并通知卖家他们需要发送该物品。



Django,当拍卖结束时,我是否要运行拍卖完成脚本,特别是当拍卖结束时间可能是移动目标时?



谢谢。

解决方案

听起来像延伸一个auction_end DateTime字段可以很容易地在bid()视图上完成



至于发送邮件的结果,您应该写一个管理脚本 http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ 检查已结束且尚未发送通知的竞价,并安排此脚本定期在cron中运行(如果必要的话)。一个例子是pinax的django通知emit_notices脚本。



http://github.com/jtauber/django-notification/blob/master/notification/management/commands/emit_notices.py



更好的是,你可能能够自己超过django通知。


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.

解决方案

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.

这篇关于Django定期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆