yield
from google.appengine.ext import ndb, deferred class User(ndb.Model): username = ndb.StringProperty() email = ndb.StringProperty() class BaseModel(ndb.Model): created_by = ndb.KeyProperty(User) edited_by = ndb.KeyProperty(User, repeated=True) class Media(BaseModel): url = ndb.StringProperty() edited_by = ndb.KeyProperty(User, repeated=True) class Address(ndb.StructuredProperty): street = ndb.StringProperty() city = ndb.StringProperty() state = ndb.StringProperty() zipcode = ndb.StringProperty() class Building(BaseModel): address = ndb.StructuredProperty(Address) size = ndb.IntegerProperty() # prevent cyclical dependencies space_keys = ndb.KeyProperty(kind=’Space’, repeated=True) owner = ndb.KeyProperty(User) def remove(self): for s in space_keys: s.get().remove() self.key.delete() class Space(BaseModel): building = ndb.KeyProperty(Building) sf_available = ndb.IntegerProperty() floor_number = ndb.IntegerProperty() suite_number = ndb.IntegerProperty() attachments = ndb.KeyProperty(Media, repeated=True) def remove(self): for a in attachments: a.delete()
remove()
ndb.transactional
class Building(BaseModel): address = ndb.StructuredProperty(Address) size = ndb.IntegerProperty() # prevent cyclical dependencies space_keys = ndb.KeyProperty(kind=’Space’, repeated=True) owner = ndb.KeyProperty(User) @ndb.transactional(xg=True) def remove(self): for s in space_keys: deferred.defer(s.get().remove) self.key.delete() class Space(BaseModel): building = ndb.KeyProperty(Building) sf_available = ndb.IntegerProperty() floor_number = ndb.IntegerProperty() suite_number = ndb.IntegerProperty() attachments = ndb.KeyProperty(Media, repeated=True) @ndb.transactional(xg=True) def remove(self): for a in attachments: deferred.defer(a.delete)
Building.remove()
get()
Space.remove()
class Building(BaseModel): address = ndb.StructuredProperty(Address) size = ndb.IntegerProperty() # prevent cyclical dependencies space_keys = ndb.KeyProperty(kind=’Space’, repeated=True) owner = ndb.KeyProperty(User) @ndb.transactional(xg=True) @ndb.tasklet def remove(self): futures = [] for s in space_keys: sp = yield s.get_async() futures.extend(sp.remove_async()) ndb.wait_all(futures) self.key.delete() class Space(BaseModel): building = ndb.KeyProperty(Building) sf_available = ndb.IntegerProperty() floor_number = ndb.IntegerProperty() suite_number = ndb.IntegerProperty() attachments = ndb.KeyProperty(Media, repeated=True) @ndb.transactional(xg=True) def remove_async(self): return ndb.delete_multi_async(self.attachments) def remove(self): ndb.Future.wait_all(self.remove_async())
Demonstrate your proficiency to design, build and manage solutions on Google Cloud Platform.