Permalink
Browse files

added taskqueues

  • Loading branch information...
1 parent 52b975d commit 1623c1f5ba59597dd7c9293cd85305b8fea95dc8 @cketcham cketcham committed Aug 27, 2009
Showing with 29 additions and 7 deletions.
  1. +4 −1 app.yaml
  2. +25 −6 measure.py
View
@@ -23,6 +23,9 @@ handlers:
- url: /measure/.*
script: measure.py
+
+- url: /process/.*
+ script: measure.py
- url: /.*
script: common/appenginepatch/main.py
@@ -46,4 +49,4 @@ skip_files: |
(.*\.md)|
(license\.txt)|
(setup.py)
- )$
+ )$
View
@@ -2,7 +2,8 @@
logging.getLogger().setLevel(logging.DEBUG)
from google.appengine.ext import webapp, db
-from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.api.labs import taskqueue
from django.utils import simplejson
from myapp.models import Campaign, Storage, Statistics
@@ -38,14 +39,30 @@ def get(self, key, path, format):
def post(self, key, path, format):
if (not key):
- return self.error(500)
-
+ return self.error(500)
+
+ process_url = self.request.path.replace('measure','process')
+
+
+ logging.debug("process_url = " + process_url)
+
+ taskqueue.add(url=process_url, params=self.request.POST)
+
+ self.response.headers['Content-Type'] = 'text/html'
+ self.response.out.write('Added to taskqueue.\n')
+
+class Process(webapp.RequestHandler):
+ def post(self,key,path,format):
+
self.campaign = Campaign.all(keys_only = True).filter('__key__ = ', db.Key(key)).get()
if (not self.campaign):
logging.warning('No campaign (%s) found.' % key)
return self.error(404)
logging.debug("%s, %s, %s" % (key, path, format))
+
+ for value in self.request.POST:
+ logging.info(value+": " + self.request.get(value))
models = []
error = False
@@ -60,7 +77,8 @@ def post(self, key, path, format):
models += _Stats.values() + stat._Hists.values()
send_to_datastore(models)
- self.response.set_status(error and 304 or 201)
+ self.response.set_status(error and 304 or 200)
+
def send_to_datastore(models):
payload = [models]
@@ -108,8 +126,9 @@ def cleanup_relations(sender, **kwargs):
logging.critical('Could not schedule a DELETE Campaign Task for Campaign (%s)' % campaign)
application = webapp.WSGIApplication(debug = os.environ['SERVER_SOFTWARE'].startswith('Dev'), url_mapping = [
- ('/measure/([^/]+)/([^\.]+)?(?:\.(.+))?', MainPage)
+ ('/measure/([^/]+)/([^\.]+)?(?:\.(.+))?', MainPage),
+ ('/process/([^/]+)/([^\.]+)?(?:\.(.+))?', Process)
])
if __name__ == "__main__":
- run_wsgi_app(application)
+ run_wsgi_app(application)

0 comments on commit 1623c1f

Please sign in to comment.