谷歌应用引擎服务之间的通信 [英] Communicating between google app engine services

查看:25
本文介绍了谷歌应用引擎服务之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构如下所示,

<预><代码>.├──应用│ ├── api│ ├──模型│ ├──服务│ │ └── lib|||__ worker.yaml|||__ 工人.py||_ main.py|_ app.yaml

我正在尝试从 worker.py 中的 app 模块(即默认模块)导入 models,例如,

 from app.models import db

但它显示No module named app.models.但是我可以在 main.py 中实现相同的效果.请注意,我正在运行 app.yamlworker.yaml 文件.

解决方案

部署后,GAE 服务/模块不会在其模块目录之外共享任何内容,该目录是其 所在的目录.yaml 文件存在.

所以 worker.py 不会看到 services 目录(worker.yaml 存在的地方)上面的任何东西,因此它不能参见模型.但是 main.py 可以,因为模型在它的 app 目录中(app.yaml 存在的地方).

如果需要,您可以在 services 内符号链接 models,请参阅 在 App Engine 模块之间共享实体

或者看看 就文件夹结构而言,Google App Engine 应用中的默认服务/模块可以是非默认服务/模块的同级吗?我如何构建多模块应用程序的示例?

My project structure looks like below,

.
├── app
│   ├── api
│   ├── models
│   ├── services
│   │   └── lib
|   |   |__ worker.yaml
|   |   |__ worker.py
|   |_ main.py
|_ app.yaml

I'm trying to import models from app module (ie, default module) in worker.py like,

from app.models import db

But it shows No module named app.models. But I can achieve the same inside main.py.Note that I'm running both app.yaml and worker.yaml files.

解决方案

When deployed, GAE Services/modules do not share anything outside their module directory, which is the directory in which their .yaml file exists.

So worker.py won't see anything above the services dir (where worker.yaml exists), thus it can't see models. But main.py can, since models is inside its app dir (where app.yaml exists).

You could symlink models inside services if you want, see Sharing entities between App Engine modules

Or maybe take a look at Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure? for an example of how I'd structure a multi-module app?

这篇关于谷歌应用引擎服务之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆