简体   繁体   中英

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. It will read database and release all crashed not closed locks on documents. This function should be executed periodically every 20 minuets, for example. As I investigated, there is no way to trigger Pub/Sub event directly by App Engine's Cron service. 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. So, I've got this error.

在此处输入图片说明

And this files.

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()

Example was taken from here 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.

Sounds like you don't have googleapiclient in your lib directory.

Couple of things:

1) try from googleapiclient import discovery <- newer version

2) $ cd to your project directory, then $ pip install -t lib google-api-python-client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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