Reputation: 6240
I have a file which will be stored in Google Storage. I then need to store data about this file in my datastore so I can find the file. If I get the file and send it to storage and something happens right after that causing no information to not be stored in the datastore the file would exist, but I would have no way to find it. Is there some technique or method to make this whole process in a "transaction"? Either everything gets inserted or nothing does?
Upvotes: 1
Views: 92
Reputation: 3443
Google Storage and Google Datastore don't provide an API to do this directly, but it can be accomplished with a 3-step dance. I'll assume that your Datastore entity is called FileInfo
. We'll need another datastore entity called PreStoreFile
.
PreStoreFile
to datastore that contains the cloud storage path where the file will be written, and a timestamp.FileInfo
and delete the PreStoreFile
from step 1.Finally, add a cron job that runs every hour or day and finds old PreStoreFile
entities and deletes them along with the corresponding datastore object.
Upvotes: 2