0

I'm trying to create multiples Google Docs in background task.

I try to use the taskqueue from Google App Engine but I mustn't understand a point as I kept getting this message :

INFO     2016-05-17 15:38:46,393 module.py:787] default: "POST /update_docs HTTP/1.1" 302 -
WARNING  2016-05-17 15:38:46,393 taskqueue_stub.py:1981] Task task1 failed to execute. This task will retry in 0.800 seconds

Here is my code. I make a multiple call to the method UpdateDocs that need to be executed from the queue.

# Create a GDoc in the queue (called by her)
class UpdateDocs(BaseHandler):
    @decorator.oauth_required
    def post(self):
        try:
            http = decorator.http()
            service = discovery.build("drive", "v2", http=http)

            # Create the file
            docs_name = self.request.get('docs_name')
            body = {
                'mimeType': DOCS_MIMETYPE,
                'title': docs_name,
            }
            service.files().insert(body=body).execute()
        except AccessTokenRefreshError:
            self.redirect("/")


# Create multiple GDocs by calling the queue
class QueueMultiDocsCreator(BaseHandler):
    def get(self):
        try:
            for i in range(5):
                name = "File_n" + str(i)
                taskqueue.add(
                    url='/update_docs',
                    params={
                        'docs_name': name,
                    })
            self.redirect('/files')
        except AccessTokenRefreshError:
            self.redirect('/')

I can see the push queue in the App Engine Console, and every tasks is inside it but they can't run, I don't get why.

Kariamoss
  • 542
  • 1
  • 9
  • 29
  • 1
    I suspect your authorisation flow fails and you get `AccessTokenRefreshError` exception, in which case you're trying to redirect (which is status 302, unacceptable from a task queue prospective). Try to replace `self.redirect("/")` in your `post()` method with something like `logging.error('AccessTokenRefreshError')`, to confirm - I'd expect the task to complete OK and the error to show up in the log. – Dan Cornilescu May 17 '16 at 17:56
  • I tried to do so but I don't get any error, still the same message. – Kariamoss May 17 '16 at 19:59
  • seems its missing all oauth code. makes no sense to redirect from a task queue. the code you are using was written for a frontend instance get. – Zig Mandel May 17 '16 at 21:33
  • The oauth code is done, I indeed used this code for a frontend instance get before I had scaling problems and the need to use a task queue. – Kariamoss May 17 '16 at 22:04

1 Answers1

-1

Kindly try to specify the worker module in your code.

As shown in Creating a new task, after calling the taskqueue.add() function, it targets the module named worker and invokes its handler by setting the url/update-counter.

class EnqueueTaskHandler(webapp2.RequestHandler):
    def post(self):
        amount = int(self.request.get('amount'))

        task = taskqueue.add(
            url='/update_counter',
            target='worker',
            params={'amount': amount})

        self.response.write(
            'Task {} enqueued, ETA {}.'.format(task.name, task.eta))

And from what I have read in this blog, a worker is one important piece of a task queue. It is a python process that reads jobs form the queue and executes them one at a time.

I hope that helps.

Teyam
  • 7,686
  • 3
  • 15
  • 22
  • Well the two methods are in the same file so I don't need to specify a target. `worker` is just their module name. – Kariamoss May 18 '16 at 10:29