问题
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:
- HTTP—invoke functions directly via HTTP requests.
- Cloud Storage
- Cloud Pub/Sub
- Firebase (DB, Storage, Analytics, Auth)
- 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:
- 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.
- 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