Automatic deletion or expiration of GAE datastore entities

Question:

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.

Asked By: new name

||

Answers:

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.

Answered By: Wooble

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

Answered By: Peter Farmer

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.

Answered By: Noah McIlraith

For future readers : now you can do it with TTL policies
https://cloud.google.com/datastore/docs/ttl

Answered By: mle