-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.py
88 lines (74 loc) · 2.69 KB
/
cron.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Copyright (C) 2010 Andrew Hill, Sander Pick
"""
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import memcache, urlfetch
import os, sys, string, Cookie, sha, time, random, cgi, urllib,urllib2
import datetime, StringIO, pickle, base64
import uuid, zipfile
import xml.etree.cElementTree as ET
import wsgiref.handlers
#from google.appengine.ext.webapp import template
from django.utils import feedgenerator, simplejson
#from django.template import Context, Template
import logging
#project module storing all the db table models
from pb.DB import *
from pb.parse.phyloxml import *
from pb.methods import *
from pb.parse.newick import *
EXAMPLE_PHYLOBOX_KEY = 'tmp9c63a1c1-9d89-4562-97cf-b1a479e56460'
class DailyCron(webapp.RequestHandler):
def get(self):
seven_days_ago = datetime.datetime.now() - datetime.timedelta(days=7)
class DeleteTemporaryAnnotations(webapp.RequestHandler):
def get(self):
self.post()
def post(self):
q = db.GqlQuery("SELECT __key__ FROM Annotation WHERE temporary = True AND addtime < :1", datetime.datetime.utcfromtimestamp(time.time()) - datetime.timedelta(days=2)).fetch(800)
try:
db.delete(q)
except:
pass
return 200
class DeleteTemporaryNodes(webapp.RequestHandler):
def get(self):
self.post()
def post(self):
d = []
q = db.GqlQuery("SELECT __key__ FROM NodeIndex WHERE temporary = True AND addtime < :1", datetime.datetime.utcfromtimestamp(time.time()) - datetime.timedelta(days=2)).fetch(500)
for n in q:
d.append(n.parent())
try:
db.delete(q)
db.delete(d)
except:
pass
return 200
class DeleteTemporaryTrees(webapp.RequestHandler):
def get(self):
self.post()
def post(self):
d = []
q = db.GqlQuery("SELECT __key__ FROM TreeIndex WHERE temporary = True AND addtime < :1", datetime.datetime.utcfromtimestamp(time.time()) - datetime.timedelta(days=2)).fetch(200)
for n in q:
d.append(n.parent())
try:
db.delete(q)
db.delete(d)
except:
pass
return 200
application = webapp.WSGIApplication([('/cron/deletetempannotations', DeleteTemporaryAnnotations),
('/cron/deletetempnodes', DeleteTemporaryNodes),
('/cron/deletetemptrees', DeleteTemporaryTrees),
('/cron/dailycron', DailyCron)],
debug=False)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()