0

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.

enter image description here

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

But, will all the libraries work if I just install them into lib folder? App engine supports not really big number of the libraries, and information about them is a bit fragmented.
App Engine is a sandbox. You can't put ANY library in the project. But, you can put most of the safe ones. If a library is not included in GAE, and not offered as one of their 3rd party libs you can include in app.yaml, then you need to add it to the project as above.
Sounds like a hack.
Not a hack. It's a managed solution, with a few limitations. But, most people never hit the limitations. It handles 99% of all requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.