-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
33 lines (28 loc) · 1.02 KB
/
worker.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
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api.labs import taskqueue
from google.appengine.api import memcache
from lifestream import *
class LifeStreamQueueWorker(webapp.RequestHandler):
def get(self):
memcache.set('fresh_count', 0)
indexes = LifeStream.instance().indexes
for index in indexes:
taskqueue.add(url='/app_worker/task', method='GET', params={'index':index})
taskqueue.add(url='/app_worker/refresh', method='GET', countdown=10)
class LifeStreamTaskWorker(webapp.RequestHandler):
def get(self):
index = int(self.request.get('index'))
LifeStream.update_feed(index)
class LifeStreamRefreshWorker(webapp.RequestHandler):
def get(self):
LifeStream.refresh_stream()
def main():
application = webapp.WSGIApplication([
('/app_worker/queue', LifeStreamQueueWorker),
('/app_worker/task', LifeStreamTaskWorker),
('/app_worker/refresh', LifeStreamRefreshWorker)
], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()