Google App Engine Python 3.7 中的多项服务

Multiple Services in Google App Engine Python 3.7

我有一个应用程序 运行 在 Python 2.7 标准框架下很好,运行 在 3.7 框架下作为两个独立的应用程序也很好,但我想不通了解如何将它们配置为具有两项服务的单个应用程序。
main.app 由以下两行组成(与 2.7 框架中的工作并行)

from app import app
from update import update

main 的 app.yaml 仅包含 运行时间:python37

main 下的两个 python 包(应用程序和更新)中的每一个都有自己的 app.yaml,正如新部署文档所说的那样。问题出在 update 包中。我曾经指定一个具有脚本的处理程序:main.update。这不再被允许(只允许自动)。请注意 app 包工作正常,因为 app 是默认入口点。我收集到当更新服务为 运行 时指定去向的新方法是使用入口点,但即使在将 gunicorn 添加到要求之后,yaml 语句

entrypoint: gunicorn b :$PORT main::update

这似乎是必需的,只是给了我一个 500 http return。我也试过 main.update 之类的变体,但无济于事。

main.py  
app.yaml  
-->/app
-----> /app/__init__.py  
-----> /app/app.yaml  
-->/update  
------> /update/__init__.py  
------> /update/app.yaml 

包和其他一些东西也有模板子目录,但是当 运行 作为单独的 versions

时它们都可以正常工作

这是我在更新目录中尝试的 yaml:

runtime: python37

service: update

entrypoint: gunicorn -b :$PORT main.update 

这是应用程序目录中的 yaml,它似乎工作正常:

runtime: python37

service: default

handlers:
- url: /static
  static_files: static/
  upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))

automatic_scaling:
  max_idle_instances: 2
  max_concurrent_requests: 12

查看您的描述并假设您的目标是类似于您引用的文档的 Example 部分中提到的目录结构,我发现了一些问题。

您在应用程序的 top/root 目录中仍有代码,位于服务目录之上 - main.pyapp.yaml 文件 - 服务无法访问此类代码。 app.yaml 文件实际上可能会导致问题,因为它 可能 意外地被解释为单一服务应用程序的 .yaml 文件。我会删除这些文件。

我只会保留在应用程序的顶级目录中 app-level optional config files and, if applicable, files intended to contain code shared by multiple services, which I would symlink inside each of the services sharing the code, see

update/app.yaml 文件中,您使用了错误的入口点配置语法:

  • 你应该在模块名称和 WSGI 应用程序变量名称之间有 一个 : 分隔符,即 main:update,而不是 main::updatemain.update。这假设你有一个 update/main.py 文件定义你的 WSGI 兼容应用程序 update (如果应用程序被称为 app 那么你会使用 main:app
  • 在一个示例中,您有 b 而不是 -b

您没有在 app/app.yaml 文件中定义入口点。您的 default 服务很可能满足自动添加默认入口点的条件,请参阅 Application startup:

  • The root of your app directory contains a main.py file with a WSGI-compatible object called app.
  • app.yaml does not contain the entrypoint field.
  • Your app does not contain Pipfile or Pipfile.lock files.

就我个人而言,我不希望依赖这种默认行为,我会明确添加入口点:

entrypoint: gunicorn -b :$PORT main:app