Thanks a lot for the advice. Still quite a novice, so can you tell me more about how to implement the function? Not entirely sure where to stash the code (function in main.py w/ all the rest of my code) or how to call it with webcron (which sounds like exactly what I need).
On Oct 6, 3:56 pm, "David Symonds" <[EMAIL PROTECTED]> wrote: > On Mon, Oct 6, 2008 at 6:12 PM, [EMAIL PROTECTED] > > > > <[EMAIL PROTECTED]> wrote: > > What's the best means of cleaning lingerers these up? Entity has a > > datetime.datetime field (called creation). > > > Will code this simple suffice: > > > def cleanDB(): > > """Clean out entities older than two hours.""" > > results = PalettesDB.all() > > for result in results: > > age = datetime.datetime.now() - result.creation > > if age.seconds > 7200: > > db.delete(result) > > > How can I call it in a cron job fashion? (It doesn't necessarily need > > to run with ever user's visit.) > > You'd be better with code like: > > def cleanDb(): > cutoff = datetime.datetime.now() - datetime.timedelta(hours=2) > for result in PalettesDB.all().filter('creation <', > cutoff).order('creation') > result.delete() > > That's much simpler, shifts the filtering burden to the datastore's > index (and thus much faster), and prevents any session from lingering > indefinitely. > > You can just hook that up to a very simple handler, and ping it every > hour or so via something like webcron. > > Dave. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---