Create/update in datastore triggers Cloud function

天大地大妈咪最大 提交于 2020-06-29 06:04:12

问题


I have a database in Google Datastore. I don't know how to use cloud functions, but i want to trigger an event after a creation or an update. Unfortunately the documentation is light on the subject : https://cloud.google.com/appengine/docs/standard/java/datastore/callbacks

I don't know how i could use @PostPut to trigger an event as soon as a line is created or updated.

Does anyone have a tutorial which a basic example ?

thank you


回答1:


Dan MacGrath provided an answer to a similar request (callbacks are indeed discussed below. Such solution doesn't exist yet. As a workaround, taking into account the current available triggers:

  1. HTTP—invoke functions directly via HTTP requests.
  2. Cloud Storage
  3. Cloud Pub/Sub
  4. Firebase (DB, Storage, Analytics, Auth)
  5. Stackdriver Logging—forward log entries to a Pub/Sub topic by creating a sink. You can then trigger the function.

I would suggest a couple of solutions:

  1. Saving something in a specific bucket from Cloud Storage every time that a line is created or updated to trigger a linked Cloud Function. You can delete the bucket contents afterwards.
  2. Create logs with the same name and then forward them to Pub/Sub, by creating a sink.

EDIT 1

  • Cloud Storage triggers for Cloud Functions: Official Google doc and tutorial with a sample code in node.js 6 in Github.
  • Cloud Pub/Sub triggers for Cloud Functions: Official Google doc and tutorial with a sample code in node.js 6 in Github (the same than before).



回答2:


Cloud Datastore does not support real-time triggers on CRUD (Create, Read, Update, Delete) events.

However, you can migrate to Cloud Firestore which does support real-time triggers for those actions (by way of Cloud Pub/Sub which can be made to invoke a Cloud Function). Cloud Firestore is the successor to Cloud Datastore and may eventually supplant it at some point in future.



来源:https://stackoverflow.com/questions/53512171/create-update-in-datastore-triggers-cloud-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!