简体   繁体   English

Google Cloud App Engine Cron无法执行python脚本

[英]Google Cloud App Engine Cron can't execute python script

I need to publish Pub/Sub event in my infrastructure. 我需要在基础架构中发布发布/订阅事件。 So, I wrote the background Google Cloud Function that subscribed on topic scan-dead-locks. 因此,我写了订阅主题scan-dead-locks的后台Google Cloud Function。 It will read database and release all crashed not closed locks on documents. 它将读取数据库并释放所有崩溃的未关闭的文档锁。 This function should be executed periodically every 20 minuets, for example. 例如,应每20分钟定期执行此功能。 As I investigated, there is no way to trigger Pub/Sub event directly by App Engine's Cron service. 根据我的调查,App Engine的Cron服务无法直接触发发布/订阅事件。 I wrote a python script that should do that (used App Engine's examples), but, the final issue left is that libraries at runtime where not found. 我编写了应该执行此操作的python脚本(使用App Engine的示例),但是剩下的最后一个问题是在运行时找不到库。 So, I've got this error. 所以,我有这个错误。

在此处输入图片说明

And this files. 和这个文件。

app.yaml app.yaml

runtime: python27
threadsafe: no

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

appengine_config.py appengine_config.py

from google.appengine.ext import vendor

vendor.add('lib')

cron.yaml 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 触发扫描死锁.py

from apiclient import discovery

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

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

Example was taken from here https://github.com/GoogleCloudPlatform/reliable-task-scheduling-compute-engine-sample . 示例来自此处https://github.com/GoogleCloudPlatform/reliable-task-scheduling-compute-engine-sample Maybe the general question that might solve the issue, how the libraries managed here (I already read documentation, but it was not really helpful)? 也许可以解决此问题的一般性问题是,库在这里是如何管理的(我已经阅读过文档,但这并没有真正的帮助)? And also I found another examples with from google.cloud import pubsub library declaration, but it didn't worked because of absent library as well. 我也from google.cloud import pubsub库声明中找到了另一个示例,但是由于缺少库,它也没有用。

Sounds like you don't have googleapiclient in your lib directory. 听起来您的lib目录中没有googleapiclient。

Couple of things: 几件事情:

1) try from googleapiclient import discovery <- newer version 1)尝试from googleapiclient import discovery <-较新的版本

2) $ cd to your project directory, then $ pip install -t lib google-api-python-client 2) $ cd到您的项目目录,然后$ pip install -t lib google-api-python-client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM