我正尝试按照以下示例在 App Engine(灵活)上使用 deferred.defer:https://cloud.google.com/appengine/articles/deferred
这是一个 Python3 应用程序。正如教程所说,我将这些行添加到 app.yaml:
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.deferred.application
login: admin
builtins:
- deferred: on
当我部署应用程序时,出现错误:
from google.appengine.ext import deferred
ModuleNotFoundError: No module named 'google.appengine'
我很困惑,因为我不明白为什么 App Engine 应用程序无法找到谷歌模块。
请您参考如下方法:
deferred 库很久以前就建立在推送任务队列之上,当时还不存在灵活的环境或它的托管 VM 前身 - 您遵循的指南实际上仅适用于标准环境。
推送任务队列在柔性环境中的支持有限。来自Task Queue节Migrating Services from the Standard Environment to the Flexible Environment :
The Task Queue service has limited availability outside of the standard environment. If you want to use the service outside of the standard environment, you can sign up for the Cloud Tasks alpha.
Outside of the standard environment, you can't add tasks to push queues, but a service running in the flexible environment can be the target of a push task. You can specify this using the
targetparameter when adding a task to queue or by specifying the defaulttargetfor the queue inqueue.yamlIn many cases where you might use pull queues, such as queuing up tasks or messages that will be pulled and processed by separate workers, Cloud Pub/Sub can be a good alternative as it offers similar functionality and delivery guarantees.
我不知道您是否/如何在标准环境之外使用带有 alpha 任务队列支持的 deferred 库本身 - 我只使用了标准环境。我只是推测您更有可能直接使用任务队列库(无论如何比 deferred 库更灵活,限制更少)。
如果您选择这两种方式中的任何一种,您将进入相当未知的领域,YMMV。祝你好运!
另一种选择是检查 pub/sub 替代方案是否适合您使用 deferred 库尝试实现的目标。无法对此发表评论,不过,我还没有使用过它。
