YoussHark
YoussHark

Reputation: 608

Create/update in datastore triggers Cloud function

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

Upvotes: 0

Views: 2723

Answers (2)

TheAddonDepot
TheAddonDepot

Reputation: 8964

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.

Upvotes: 3

Rubén C.
Rubén C.

Reputation: 1098

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

Upvotes: 3

Related Questions