Google App Engine deferred.defer()错误404

时间:2014-03-11 01:36:33

标签: python google-app-engine

我尝试使用deferred.defer()在任务队列中运行任务。该任务将添加到默认任务队列,但任务失败并显示404错误。

这是处理程序:

import webapp2
import models

import defer_ajust_utils

from google.appengine.ext import ndb
from google.appengine.ext import deferred

class ajust_utils(webapp2.RequestHandler):
  def get(self):
    deferred.defer(defer_ajust_utils.DoTheJob)

application = webapp2.WSGIApplication([('/ajust_utils', ajust_utils)], debug=True)

这是模块 defer_ajust_utils

import logging
import models 
from google.appengine.ext import ndb

def DoTheJob():
  logging.info("Debut de la mise a jour des utilisateurs")
  utilisateurs = models.Utilisateur.query()
  utilisateurs = utilisateurs.fetch()

  for utilisateur in utilisateurs:
    utilisateur.produire_factures_i = False
    utilisateur.put()  

  logging.info("Fin de la mise a jour des utilisateurs")

我的 app.yaml 文件:

application: xxxx
version: dev
runtime: python27
api_version: 1
threadsafe: yes

builtins:
- deferred: on

handlers:
- url: /ajust_utils
  script : tempo_ajuster_utils.application
  login: admin

这是日志:

0.1.0.2 - - [10/Mar/2014:17:50:45 -0700] "POST /_ah/queue/deferred HTTP/1.1" 404 113
"http://xxxx.appspot.com/ajust_utils" "AppEngine-Google;
(+http://code.google.com/appengine)" "xxxx.appspot.com" ms=6 cpu_ms=0 
cpm_usd=0.000013 queue_name=default task_name=17914595085560382799 
app_engine_release=1.9.0 instance=00c61b117c0b3648693af0563b92051423b3cb

谢谢你的帮助!!

3 个答案:

答案 0 :(得分:6)

如果您使用git进行push-to-deploy,那么当您添加“内置”功能时,部分到app.yaml,例如

builtins: - deferred: on

你需要做一个正常的'在运行应用程序之前进行gcloud部署。否则它将不会更新正在运行的应用程序,这会导致/ _ah / queue / deferred

的404错误

这是一个开放的错误,因此投票支持它可能会得到修复。 https://code.google.com/p/googleappengine/issues/detail?id=10139

答案 1 :(得分:3)

我收到同样的错误。

https://cloud.google.com/appengine/articles/deferred

似乎是文档缺陷

我查看了源代码并找到了以下内容,其中没有任何文档:

In order for tasks to be processed, you need to set up the handler. Add the
following to your app.yaml handlers section:

handlers:
- url: /_ah/queue/deferred
  script: $PYTHON_LIB/google/appengine/ext/deferred/handler.py
  login: admin

当我在app.yaml中设置threadsafe: true时,我必须添加以下处理程序:

- url: /_ah/queue/deferred
  script: google.appengine.ext.deferred.deferred.application
  login: admin

然后延迟的任务队列开始工作并停止了404。

答案 2 :(得分:-1)

我认为你必须在app.yaml中添加选项deferred:on到你的应用程序“builtin”选项以下摘录自

https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Builtin_handlers

builtins:
- deferred: on

The following builtin handlers are available:
admin_redirect - For production App Engine, this results in a redirect from /_ah/admin to the admin console. This builtin has no effect in the development web server.
appstats - Enables Appstats at /_ah/stats/, which you can use to measure your application's performance. In order to use Appstats, you also need to install the event recorder.
deferred - Enables the deferred handler at /_ah/queue/deferred. This builtin allows developers to use deferred.defer() to simplify the creation of Task Queue tasks. Also see Background work with the deferred library.