Added iterator to objectstore

Since the objectstore mixin uses a iterable to store it's data,
it was easy to add an __iter__ to the objectstore class itself.
This commit is contained in:
Hemna 2024-02-24 14:27:39 -05:00
parent e89f8a805b
commit df2798eafb
1 changed files with 8 additions and 1 deletions

View File

@ -28,6 +28,9 @@ class ObjectStoreMixin:
def __len__(self):
return len(self.data)
def __iter__(self):
return iter(self.data)
def get_all(self):
with self.lock:
return self.data
@ -96,11 +99,15 @@ class ObjectStoreMixin:
LOG.debug(
f"{self.__class__.__name__}::Loaded {len(self)} entries from disk.",
)
LOG.debug(f"{self.data}")
#LOG.debug(f"{self.data}")
else:
LOG.debug(f"{self.__class__.__name__}::No data to load.")
except (pickle.UnpicklingError, Exception) as ex:
LOG.error(f"Failed to UnPickle {self._save_filename()}")
LOG.error(ex)
self.data = {}
else:
LOG.debug(f"{self.__class__.__name__}::No save file found.")
def flush(self):
"""Nuke the old pickle file that stored the old results from last aprsd run."""