def purge( self, *, body: bodies.Body, patch: patches.Patch, storage: progress.ProgressStorage, ) -> None: # Purge only our own handlers. Ignore others (e.g. other operators). for handler_id in self.keys(): storage.purge(key=handler_id, body=body, patch=patch) storage.flush()
def store( self, body: bodies.Body, patch: patches.Patch, storage: progress.ProgressStorage, ) -> None: for handler_id, handler_state in self.items(): full_record = handler_state.for_storage() pure_record = handler_state.as_in_storage() if pure_record != handler_state._origin: storage.store(key=handler_id, record=full_record, body=body, patch=patch) storage.flush()
def from_storage( cls, *, body: bodies.Body, storage: progress.ProgressStorage, handlers: Collection[handlers_.BaseHandler], ) -> "State": handler_states: Dict[handlers_.HandlerId, HandlerState] = {} for handler in handlers: content = storage.fetch(key=handler.id, body=body) handler_states[handler.id] = (HandlerState.from_storage(content) if content else HandlerState.from_scratch()) return cls(handler_states)
def from_storage( cls, *, body: bodies.Body, storage: progress.ProgressStorage, handlers: Iterable[handlers_.BaseHandler], ) -> "State": handler_ids = {handler.id for handler in handlers} handler_states: Dict[ids.HandlerId, HandlerState] = {} for handler_id in handler_ids: content = storage.fetch(key=handler_id, body=body) if content is not None: handler_states[handler_id] = HandlerState.from_storage(content) return cls(handler_states)
def purge( self, *, body: bodies.Body, patch: patches.Patch, storage: progress.ProgressStorage, handlers: Iterable[handlers_.BaseHandler], ) -> None: # Purge only our own handlers and their direct & indirect sub-handlers of all levels deep. # Ignore other handlers (e.g. handlers of other operators). handler_ids = {handler.id for handler in handlers} for handler_id in handler_ids: storage.purge(key=handler_id, body=body, patch=patch) for handler_id, handler_state in self.items(): if handler_id not in handler_ids: storage.purge(key=handler_id, body=body, patch=patch) for subref in handler_state.subrefs: storage.purge(key=subref, body=body, patch=patch) storage.flush()