Question

I am writing my first "serious" application with AppEngine and have run into some problems with the task queue.

I have read and reproduced the example code that is given in the appengine docs.

When I tried to add a Task to a custom Queue though it doesn't seem to work for me as it works for others:

What I do is:

from google.appengine.api import taskqueue

def EnterQueueHandler(AppHandler):
    def get(self):
        #some code
    def post(self):
        key = self.request.get("value")
        task = Task(url='/queue', params={'key':key})
        task.add("testqueue")
        self.redirect("/enterqueue")

And then I have a handler set for "/queue" that does stuff.

The problem is that this throws the following error:

NameError: global name 'Task' is not defined

Why is that? It seems to me I am missing something basic, but I can't figure out what. It says in the docs that the Task-Class is provided by the taskqueue module.

By now I have figured out that it works if I replace the two task-related lines in the code above with the following:

taskqueue.add(queue_name="testqueue", url="/queue", params={"key":key})

But I would like to understand why the other method doesn't work nonetheless. It would be very nice if someone could help me out here.

Était-ce utile?

La solution

From the documentation

Task is provided by the google.appengine.api.taskqueue module.

Since you have already imported

from google.appengine.api import taskqueue

You can replace this line:

task = Task(url='/queue', params={'key':key})

with

task = taskqueue.Task(url='/queue', params={'key':key})

Autres conseils

I think the reason is does not work is "Task" is not imported. Below is an example that i use all of the time successfully. Looks just like yours but my import is different.

from google.appengine.api.taskqueue import Task

task = Task(
    url=url,
    method=method,
    payload=payload,
    params=params,
    countdown=0
)

task.add(queue_name=queue)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top