Skip to content

Commit f81552c

Browse files
author
Jon Wayne Parrott
committed
Fixing async task queue sample
Change-Id: I7f4deb12a657f4bc9dbfe2c244c0ebd50e490ce4
1 parent 2a55183 commit f81552c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

appengine/taskqueue/counter/application.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ def post(self):
5252
'Task {} enqueued, ETA {}.'.format(task.name, task.eta))
5353

5454

55+
# AsyncEnqueueTaskHandler behaves the same as EnqueueTaskHandler, but shows
56+
# how to queue the task using the asyncronous API. This is not wired up by
57+
# default. To use this, change the MainPageHandler's form action to
58+
# /enqueue_async
5559
class AsyncEnqueueTaskHandler(webapp2.RequestHandler):
5660
def post(self):
5761
amount = int(self.request.get('amount'))
5862

59-
future = taskqueue.add_async(
63+
queue = taskqueue.Queue(name='default')
64+
task = taskqueue.Task(
6065
url='/update_counter',
6166
target='worker',
6267
params={'amount': amount})
6368

64-
task = future.wait()
69+
rpc = queue.add_async(task)
70+
71+
# Wait for the rpc to complete and return the queued task.
72+
task = rpc.get_result()
6573

6674
self.response.write(
6775
'Task {} enqueued, ETA {}.'.format(task.name, task.eta))
@@ -70,5 +78,5 @@ def post(self):
7078
app = webapp2.WSGIApplication([
7179
('/', MainPageHandler),
7280
('/enqueue', EnqueueTaskHandler),
73-
('/enqueue_async', EnqueueTaskHandler)
81+
('/enqueue_async', AsyncEnqueueTaskHandler)
7482
], debug=True)

0 commit comments

Comments
 (0)