GAE 数据存储实体的自动删除或过期
我正在使用 GAE 构建我的第一个应用程序,以允许用户进行选举,并为每次选举创建一个选举实体。
为了避免存储太多数据,我想在一段时间后(例如选举结束后三个月)自动删除选举实体。 GAE 中可以自动执行此操作吗?或者我需要手动执行此操作?
如果重要的话,我正在使用 Python 界面。
I'm building my first app with GAE to allow users to run elections, and I create an Election entity for each election.
To avoid storing too much data, I'd like to automatically delete an Election entity after a certain period of time -- say three months after the end of the election. Is it possible to do this automatically in GAE? Or do I need to do this manually?
If it matters, I'm using the Python interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您在实体上有一个 DateProperty 来指示选举何时结束,您可以每晚对任何超过 3 个月的任务进行 cron 作业搜索并将其删除。
Assuming you have a DateProperty on the entities indicating when the election ended, you can have a cron job search for any older than 3 months every night and delete them.
您可以使用应用程序引擎“cron”工具定期运行任务。每个任务基本上都是一个由 cronjob 调用的 URL,因此您只需对它们进行编码,就像从浏览器中调用它们一样。
请参阅:http://code.google.com/appengine/docs/python /config/cron.html
You can use the app engine "cron" facility to run tasks periodically. Each task is basically a URL which gets called by the cronjob, so you just code them as if you would call them from a browser.
See: http://code.google.com/appengine/docs/python/config/cron.html
对于未来的读者:现在您可以使用 TTL 策略来做到这一点
https://cloud.google.com/datastore/docs/ttl
For future readers : now you can do it with TTL policies
https://cloud.google.com/datastore/docs/ttl
您应该同时使用数据存储区统计信息库和< href="http://code.google.com/appengine/docs/python/config/cron.html" rel="nofollow">cron 服务,用于定期检查存储消耗并删除其中最旧的选举数据存储区。
这样,您将保持在目标消费范围内,但仍会在方便时保留信息。
You should make use of both the datastore statistics library and the cron service to periodically check the storage consumption and delete the oldest elections from the datastore.
This way you will remain under your target consumption but still retain information for as long as it is convenient.