2

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.

3
  • replace Task with taskqueue.Task Commented Sep 23, 2013 at 15:01
  • Wow, thanks! That was really fast! And it really was something basic...how can I mark your comment as the solution? Commented Sep 23, 2013 at 15:06
  • Glad it helped. I answered your question. Now, you can marked the answer as accepted. Commented Sep 23, 2013 at 15:08

2 Answers 2

1

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})
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.