在 Django 中的特定时间触发通知
我创建了一个 iPhone 应用程序,希望在自定义时间接收通知。后端 Django 应用程序有一个事件队列,其中包含应将事件提醒推送到 iPhone 客户端的日期。这就像 eBay 的 Watch Alert;当您关注的商品的竞价期即将结束时,eBay 会向您发送一条消息提醒您。
使用 Django 在后端实现此功能的最佳方法是什么?我对使用 cron 很犹豫,因为会有大量事件,而且我不想为每个事件安排一个 cron 作业。此外,我希望事件通知系统的模型(乐意使用适配器)使用事件队列,这样如果事件被删除或更新,事件通知系统将不会使用过时的模型数据。
I created an iPhone application that I want to receive notifications at a custom time. The backend Django application has a queue of events with dates when the event reminder should be pushed to the iPhone client. This is this like a Watch Alert from eBay; when the bidding period of a watched item is about to close, eBay sends you a message reminding you.
What is the best way to implement this on the backend using Django? I am hesitant to use cron, because there will be a large number of events, and I do not want to schedule a cron job for each event. Additionally, I want the event notification system's model (happy to use an Adapter) to use the event queue, so that if an event is removed or updated, the event notification system will not use outdated model data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cron 是执行此操作的正确工具,但您不希望每个事件都有单独的 cron 条目。相反,cron 应该触发一个 Django 脚本,该脚本检查数据库中是否有任何到期的通知,并触发它们。
cron is the right tool for this, but you don't want a separate cron entry for each event. Instead, cron should trigger a Django script that checks the database for any notifications that are due, and fires them.
您可能需要考虑 Celery 及其定期计划任务。然后,您可以直接从 Python 代码安排任务,而无需为每个任务添加 crontab 条目。
You may want to consider Celery and its periodic scheduled tasks. Then you could schedule the tasks directly from your Python code, without having to add a crontab entry for each one.