2017-06-05 88 views
0

我需要在我的基础结构中发布Pub/Sub事件。因此,我编写了订阅主题扫描死锁的背景Google Cloud Function。它将读取数据库并释放文件上所有崩溃的未关闭的锁。例如,该功能应该每20个分钟周期执行一次。正如我所研究的,App Engine的Cron服务无法直接触发Pub/Sub事件。我写了一个应该这样做的python脚本(使用App Engine的例子),但最后的问题是运行时找不到的库。所以,我有这个错误。Google Cloud App Engine Cron无法执行python脚本

enter image description here

和这个文件。

的app.yaml

runtime: python27 
threadsafe: no 

handlers: 
    - url: /trigger-scan-dead-locks 
    script: trigger-scan-dead-locks.py 
    login: admin 

appengine_config.py

from google.appengine.ext import vendor 

vendor.add('lib') 

cron.yaml

cron: 
- description: scan for dead locks and release locks 
    url: /trigger-scan-dead-locks 
    schedule: every 20 mins 

trigger-scan-dead-locks.py

from apiclient import discovery 

pubsub = discovery.build('pubsub', 'v1') 

pubsub.projects().topics().publish(topic="scan-dead-locks").execute() 

实施例从这里https://github.com/GoogleCloudPlatform/reliable-task-scheduling-compute-engine-sample服用。 也许可以解决这个问题的一般问题,图书馆如何在这里管理(我已经阅读过文档,但它并不真正有帮助)?另外我还发现了另一个使用from google.cloud import pubsub库声明的例子,但由于缺少库也无效。

回答

1

听起来像你在你的lib目录中没有googleapiclient。

几件事情:

1)尽量from googleapiclient import discovery < - 新版本

2)$ cd到项目目录,然后$ pip install -t lib google-api-python-client

+0

但是,将所有的库工作,如果我只是将它们安装到lib文件夹? App引擎不支持大量的库,并且有关它们的信息有点碎片化。 – QuestionAndAnswer

+0

App Engine是一个沙箱。您不能将任何库放入项目中。但是,你可以把大多数安全的。如果一个库不包含在GAE中,而不是作为其第三方库中的一个提供的,你可以将其包含在app.yaml中,那么你需要将它添加到上面的项目中。 – GAEfan

+0

听起来像一个黑客。 – QuestionAndAnswer