Skip to content

Commit

Permalink
Fixing async task queue sample
Browse files Browse the repository at this point in the history
Change-Id: I7f4deb12a657f4bc9dbfe2c244c0ebd50e490ce4
  • Loading branch information
Jon Wayne Parrott committed Apr 15, 2016
1 parent 2a55183 commit f81552c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions appengine/taskqueue/counter/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,24 @@ def post(self):
'Task {} enqueued, ETA {}.'.format(task.name, task.eta))


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

future = taskqueue.add_async(
queue = taskqueue.Queue(name='default')
task = taskqueue.Task(
url='/update_counter',
target='worker',
params={'amount': amount})

task = future.wait()
rpc = queue.add_async(task)

# Wait for the rpc to complete and return the queued task.
task = rpc.get_result()

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

0 comments on commit f81552c

Please sign in to comment.