def take_snapshot(entity, timestamp=None): # Make the 'stored entity ID' for the entity, it is used as the Snapshot 'entity ID'. # Create the snapshot event. snapshot = Snapshot( entity_id=entity.id, timestamp=timestamp, topic=topic_from_domain_class(entity.__class__), # Todo: This should be a deepcopy. state=entity.__dict__.copy(), ) publish(snapshot) # Return the event. return snapshot
def take_snapshot(entity, at_event_id): # Make the 'stored entity ID' for the entity, it is used as the Snapshot 'entity ID'. id_prefix = id_prefix_from_entity(entity) stored_entity_id = make_stored_entity_id(id_prefix, entity.id) # Create the snapshot event. snapshot = Snapshot( entity_id=stored_entity_id, domain_event_id=at_event_id, topic=topic_from_domain_class(entity.__class__), attrs=entity.__dict__.copy(), ) publish(snapshot) # Return the event. return snapshot
def take_snapshot(self, entity_id, entity, last_event_version): """ Takes a snapshot by instantiating and publishing a Snapshot domain event. :rtype: Snapshot """ # Create the snapshot event. snapshot = Snapshot( originator_id=entity_id, originator_version=last_event_version, topic=get_topic(entity.__class__), state=None if entity is None else deepcopy(entity.__dict__)) # Publish the snapshot event. publish(snapshot) # Return the snapshot event. return snapshot
def take_snapshot(self, entity_id, entity, last_event_version): """ Creates a Snapshot from the given state, and appends it to the snapshot store. :rtype: Snapshot """ # Create the snapshot. snapshot = Snapshot( originator_id=entity_id, originator_version=last_event_version, topic=get_topic(entity.__class__), state=None if entity is None else deepcopy(entity.__dict__) ) self.snapshot_store.store(snapshot) # Return the snapshot. return snapshot