I’m working on a project where I need to generate several Google Documents through background processing. I decided to implement the taskqueue feature from Google App Engine for this purpose, but something isn’t working correctly.
Whenever I try to run my tasks, I keep seeing this error pattern in my logs:
INFO 2016-05-17 15:38:46,393 module.py:787] default: "POST /create_document HTTP/1.1" 302 -
WARNING 2016-05-17 15:38:46,393 taskqueue_stub.py:1981] Task document_task failed to execute. This task will retry in 0.800 seconds
Here’s my implementation. I have a handler called CreateDocument that should process individual document creation requests from the queue:
# Handler for creating individual documents (processes queue tasks)
class CreateDocument(BaseHandler):
@decorator.oauth_required
def post(self):
try:
http_auth = decorator.http()
drive_service = discovery.build("drive", "v2", http=http_auth)
# Generate the document
document_title = self.request.get('document_title')
file_body = {
'mimeType': DOCS_MIMETYPE,
'title': document_title,
}
drive_service.files().insert(body=file_body).execute()
except AccessTokenRefreshError:
self.redirect("/")
# Handler that queues multiple document creation tasks
class BatchDocumentGenerator(BaseHandler):
def get(self):
try:
for counter in range(5):
filename = "Document_" + str(counter)
taskqueue.add(
url='/create_document',
params={
'document_title': filename,
})
self.redirect('/documents')
except AccessTokenRefreshError:
self.redirect('/')
I can see all the tasks appearing in the App Engine Console’s task queue section, but they just sit there and won’t execute properly. What could be causing this issue?