【发布时间】:2016-05-17 15:48:23
【问题描述】:
我正在尝试在后台任务中创建多个 Google 文档。
我尝试使用Google App Engine 中的taskqueue,但我不能理解一点,因为我不断收到此消息:
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
这是我的代码。我多次调用需要从队列中执行的方法UpdateDocs。
# 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('/')
我可以在 App Engine 控制台中看到推送队列,每个任务都在其中,但它们无法运行,我不明白为什么。
【问题讨论】:
-
我怀疑您的授权流程失败并且您收到
AccessTokenRefreshError异常,在这种情况下您正在尝试重定向(这是状态 302,从任务队列预期来看是不可接受的)。尝试将post()方法中的self.redirect("/")替换为logging.error('AccessTokenRefreshError')之类的内容,以确认 - 我希望任务可以正常完成并且错误会显示在日志中。 -
我尝试这样做,但我没有收到任何错误,仍然是相同的消息。
-
似乎缺少所有 oauth 代码。从任务队列重定向是没有意义的。您使用的代码是为前端实例获取编写的。
-
oauth 代码已经完成,在遇到扩展问题和需要使用任务队列之前,我确实将此代码用于前端实例获取。
标签: python google-app-engine google-drive-api task-queue