Skip to content

Instantly share code, notes, and snippets.

@AniX
Created January 16, 2014 00:47
Show Gist options
  • Save AniX/8447779 to your computer and use it in GitHub Desktop.
Save AniX/8447779 to your computer and use it in GitHub Desktop.
Code example how to implement a cron-job that deletes expired tokens in Google App Engine Python apps using webapp2 based authentication See http://blog.abahgat.com/2013/01/07/user-authentication-with-webapp2-on-google-app-engine/
import datetime
from google.appengine.ext import ndb
# eventually import custom User class here and adjust paths below
# parameter in timedelta() assumes that tokens expire ~3 months after creation:
expiredTokens = User.token_model.query(User.token_model.created <= (datetime.datetime.utcnow() - datetime.timedelta(3*365/12)))
# delete the tokens in bulks of 100:
while expiredTokens.count() > 0:
keys = expiredTokens.fetch(100, keys_only=True)
ndb.delete_multi(keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment