Skip to content

Commit

Permalink
Add is_initialized() to base persister interface for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitgupta-it committed Nov 9, 2024
1 parent 5e31502 commit f8e3145
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions burr/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,10 +2207,14 @@ def with_state_persister(
"""
if on_every != "step":
raise ValueError(f"on_every {on_every} not supported")
if hasattr(persister, 'initialize') and not persister.is_initialized():
raise RuntimeError(
"Uninitialized persister. Make sure to call .initialize() before passing it to the ApplicationBuilder."
)

# Check if 'is_initialized' exists and whether it returns False, indicating the persister is uninitialized
if hasattr(persister, 'is_initialized'):
if not persister.is_initialized():
raise RuntimeError(
"RuntimeError: Uninitialized persister. Make sure to call .initialize() before passing it to the ApplicationBuilder"
)
# If the persister is valid and initialized, add it to lifecycle adapters
if not isinstance(persister, persistence.BaseStateSaver):
self.lifecycle_adapters.append(persister)
else:
Expand Down
6 changes: 5 additions & 1 deletion burr/core/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class BaseStatePersister(BaseStateLoader, BaseStateSaver, metaclass=ABCMeta):
Extend this class if you want an easy way to implement custom state storage.
"""

pass
def is_initialized(self) -> bool:
"""Check if the persister has been initialized. Default behavior is False.
Persisters that require initialization can override this method.
"""
return False


class PersisterHook(PostRunStepHook):
Expand Down

0 comments on commit f8e3145

Please sign in to comment.