Google App Engine deferred.defer()错误404

Sly*_*ult 9 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)
Run Code Online (Sandbox Code Playgroud)

这是模块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")
Run Code Online (Sandbox Code Playgroud)

还有我的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
Run Code Online (Sandbox Code Playgroud)

这是日志:

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
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!!

nik*_*nik 6

如果您使用git进行push-to-deploy,那么当您向app.yaml添加"内置"部分时,例如

builtins: - deferred: on

在运行应用程序之前,您需要执行"正常"gcloud部署.否则它将不会更新正在运行的应用程序,这会导致/ _ah/queue/deferred出现404错误

有一个开放的bug,所以投票给它,它可能会得到修复.https://code.google.com/p/googleappengine/issues/detail?id=10139


小智 -1

我认为您必须将选项 deferred: 添加到 app.yaml 中的应用程序“内置”选项中,这是摘录

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.
Run Code Online (Sandbox Code Playgroud)