I'm building my first app with GAE to allow users to run elections, and I create an Election entity for ea开发者_高级运维ch 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.
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.
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
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.
For future readers : now you can do it with TTL policies https://cloud.google.com/datastore/docs/ttl
精彩评论