Commits

Miki Tebeka committed be7cc99

Use task queue

Comments (0)

Files changed (1)

 from google.appengine.api import users
 from google.appengine.ext import db
 from google.appengine.api import memcache
+from google.appengine.api import taskqueue
 import jinja2
 
 from os.path import dirname
             long_url = str(url.long)
             memcache.set(short_url, long_url)
 
+        # Increment count async
+        taskqueue.add(url=INC_URL, params={'url' : short_url})
+
+        self.redirect(long_url)
+
+INC_URL = '/_worker/hit'
+class Hit(webapp.RequestHandler):
+    '''Hit worker, will increment hit count for url.'''
+    def post(self):
+        short_url = self.request.get('url')
         inc_hits(short_url)
-        self.redirect(long_url)
 
 app = webapp.WSGIApplication([
     ('/', Home),
+    (INC_URL, Hit),
     ('/([a-zA-Z0-9]+)', Redirect),
 ], debug=True)