0

djangoappengine.views.warmup does its job of loading all Django apps when GAE sends a warmup request. If GAE does not send a warmup request, either due to request spike or because warmup service is not enabled, then when does INSTALLED_APPS get imported? I see that djangoappengine.deferred.handler.application loads all INSTALLED_APPS, but djangoappengine.main.application does not.

The problem I'm having is that if there is no warmup request, then either that first loading request handler or subsequent request handler may need a nonrel-search model field which is not yet registered, because search was not imported via INSTALLED_APPS and thus autodiscover() did not yet run.

My settings MIDDLEWARE_CLASSES does have 'autoload.middleware.AutoloadMiddleware', so I would think that it could load that way without warmup, but it's not.

What is the solution to make sure everything is loaded before handling any requests?

4

1 回答 1

0

解决方案是在站点的 urls.py 中调用 search.autodiscover(),此外还有 INSTALLED_APPS 中的自动加载和搜索,以及 MIDDLEWARE_CLASSES 中的 autoload.middleware.AutoloadMiddleware。

原因是虽然 djangoappengine.views.warmup 和 djangoappengine.deferred.handler.application 加载 INSTALLED_APPS 并导致 search.autodiscover() 被调用,但 djangoappengine.main.application 并没有这样做。因此,如果您的 GAE 实例直接由请求启动,则不会注册搜索索引。因此,urls.py 中的 search.autodiscover() 是注册这些索引所必需的。

于 2014-01-26T20:29:36.080 回答