forked from freshplanet/AppEngine-Deferred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleApp.py
32 lines (21 loc) · 827 Bytes
/
sampleApp.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
import logging
from google.appengine.ext import ndb
import webapp2
import tasks
class DemoHandler(webapp2.RequestHandler):
"""
Basic handler that trigger some code to be executed later.
"""
def get(self):
# If you have the ndb.toplevel middleware you can just fire-and-forget:
tasks.addTask('default', doStuff, "foo")
# Otherwise it is recommended to call get_result before exiting the request handler:
tasks.addTask('default', doStuff, "bar").get_result()
self.response.write("Task enqueued")
def doStuff(what):
logging.info("Doing stuff: %s", what)
app = webapp2.WSGIApplication([
webapp2.Route('/', DemoHandler),
webapp2.Route('/_cb/deferred/<module>/<name>', tasks.DeferredHandler)
])
app = ndb.toplevel(app)