开发者

Django 1.3, how to signal when a post has ended like on ebay?

I'm totally confused and have no idea how to do this, so please forgive me if my description/information is bad.

So I want say to do a notification via django-notification or simply send an e-mail to one of my user when a post of his had ended like on ebay. In my database I have a model which stores the datetime of when the post is going to end, but I'm not sure how to effectively check or store a signal or s开发者_如何学运维omething which would alert the system to alert the user when the current time is > than the end datetime.

thanks!

Since I want to send an email/notification the second a post ends, I don't think I can use a scheduler to check if any post had ended, I believe this would be too inefficient, because I would have to check like every second, but like I said above, I'm not sure about anything...


You could use django-celery -- connect a post_save handler that checks if created is True, and if so schedules a Task that'll notify the user at the correct time (using the eta keyword arg).


It sounds to me like you've at least thought through some solutions. One thing to keep in mind though is that Django, being a web framework, is a stateless "machine". In a nutshell that means it isn't "running" at the split second that a post expires (or rather you can't assume that a request is being sent from a browser at the split second a post expires). This means that using Django to signal/send the notification is not appropriate.

However, since you know exactly when the email should be sent, it should be possible to queue the notification in Django as soon as the post is created. Some outside "program" will then have to process the queue to actually send the notification...there are all kinds of creative ways to do this, but you can certainly use python to do it.

If you want to consider using a Message Queue, take a look at RabbitMQ http://nathanborror.com/posts/2009/may/20/working-django-and-rabbitmq/


As other have said, the best solution is django-celery (https://github.com/ask/django-celery) but it's a little heavyweight if you are low on resources.

In a similar need, I have a middleware that checks the conditions and executes the needed operations (which, in my case, are just changing a boolean in some records of the database). This works for me because until someone actually access the data there is no need to change it, and because the "task" is just one UPDATE query, so it's not an unbearable load.

Otherwise you can set up a cron job every short time (1 minute? 5 minutes?) and check conditions and do consequences.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜