Reputation: 167
hint: this doesn't need a code sample
I'am working with google cloud storage and cloud functions, the case demands triggering the function when an object is uploaded via (Object finalized
) event, the chain goes as listening to the event from cloud functions, generate a random string, call some api that commits to a db, and rename the same object with the random string attached, when this happens -renaming the object via bucket.rename_blob
- , google cloud storage triggers the finalize event again thus the same function is called again in a randomly-ended loop (noticed uploading an object generates about 23 names in the db), anyway to stop propagating the event when the object is renamed?
Upvotes: 1
Views: 877
Reputation: 83191
As we can read in the doc for bucket.rename_blob
, this method "copies blob to the same bucket with a new name, then deletes the blob". This is why your Cloud Function is triggered again and again, since each time you rename an Object a new Object is created, which triggers the finalized
event.
The only way I can see is to store in a DB the new Object name and, in the Cloud Function, check if this name is present in the DB: If it is present you don't execute the Cloud Function business logic since this Object name is the one of a renamed object.
You can very well use Cloud Firestore as the DB to store those names, or any other DB of your choice
Upvotes: 3