Skip to content Skip to sidebar Skip to footer

Google App Engine Taskqueues

Have some problems using taskqueues in google app engine. I tried doing the same as in this site: https://developers.google.com/appengine/docs/python/taskqueue/overview-push But it

Solution 1:

By default, task queues send a POST request to whatever handler is mapped to the URL (in your case /worker, which should be mapped to CounterWorker). Therefore you need to define a post method in your CounterWorker method.

classCounterWorker(webapp.RequestHandler):defpost(self):
    deftxn():
      logging.info("bla")
    db.run_in_transaction(txn)

Your comment suggests that tasks should just run 1/s. You can define this in your queue.yaml config file.

Also, taskqueues have 10 minute timeout, so they wont run forever. To rectify this, try chaining them or use the deferred API. For long running processes, the backends API is probably a better fit.

Solution 2:

If you just want to execute tasks "vanilla" then have a look at the deferred functions.

Background work with the deferred library

from google.appengine.ext import deferred

  defdo_something_expensive(a, b, c=None):
      logging.info("Doing something expensive!")
      # Do your work here# Somewhere else
  deferred.defer(do_something_expensive, "Hello, world!", 42, c=True)

You won't need a url/webapp handler as you can pass the function directly.

Post a Comment for "Google App Engine Taskqueues"