Miki Tebeka avatar 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.