-
Notifications
You must be signed in to change notification settings - Fork 11
/
downerclear.py
32 lines (23 loc) · 896 Bytes
/
downerclear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
import base64, cgi, logging, urllib, wsgiref.handlers
from datetime import *
from itertools import *
from downer import *
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import urlfetch
class DownerClear(webapp.RequestHandler):
def get(self):
hour_ago = datetime.now() + timedelta(minutes=-60)
cleared = 0
query = db.GqlQuery("SELECT __key__ FROM Downer WHERE down_at < :1", hour_ago)
results = query.fetch(500)
results_size = len(results)
db.delete(results)
cleared += results_size
return self.response.out.write("cleared %d" % cleared)
def main():
application = webapp.WSGIApplication([('/_downerclear', DownerClear)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)