diff --git a/silverback/application.py b/silverback/application.py index 98960dab..ed32b6de 100644 --- a/silverback/application.py +++ b/silverback/application.py @@ -80,8 +80,8 @@ def on_startup(self) -> Callable: Usage example:: @app.on_startup() - def do_something_on_startup(state): - ... # Can provision resources, or add things to `state`. + def do_something_on_startup(startup_state): + ... # Reprocess missed events or blocks """ return self.broker.task(task_name="silverback_startup") @@ -92,8 +92,8 @@ def on_shutdown(self) -> Callable: Usage example:: @app.on_shutdown() - def do_something_on_shutdown(state): - ... # Update some external service, perhaps using information from `state`. + def do_something_on_shutdown(): + ... # Record final state of app """ return self.broker.task(task_name="silverback_shutdown") diff --git a/silverback/persistence.py b/silverback/persistence.py index 48b1cb60..254b7317 100644 --- a/silverback/persistence.py +++ b/silverback/persistence.py @@ -8,7 +8,7 @@ from taskiq import TaskiqResult from typing_extensions import Self # Introduced 3.11 -from .types import IntOrNone, SilverbackIdent, SilverbackSettings +from .types import IntOrNone, SilverbackIdent, ISilverbackSettings class SilverbackState(BaseModel): @@ -57,7 +57,7 @@ def from_taskiq( class BasePersistentStorage(ABC): - def __init__(self, settings: SilverbackSettings): + def __init__(self, settings: ISilverbackSettings): self.settings = settings @abstractmethod diff --git a/silverback/settings.py b/silverback/settings.py index ef1ca9f0..96694e60 100644 --- a/silverback/settings.py +++ b/silverback/settings.py @@ -68,7 +68,6 @@ def get_broker(self) -> AsyncBroker: return broker def get_network_choice(self) -> str: - # return self.NETWORK_CHOICE or self.network_manager.default_ecosystem.name return self.NETWORK_CHOICE or self.network_manager.network.choice def get_persistent_storage(self) -> Optional[BasePersistentStorage]: diff --git a/silverback/types.py b/silverback/types.py index ba162b9f..76e77d05 100644 --- a/silverback/types.py +++ b/silverback/types.py @@ -8,7 +8,10 @@ IntOrNone = Union[int, None] -class SilverbackSettings(Protocol): +class ISilverbackSettings(Protocol): + """Loose approximation of silverback.settings.Settings. If you can, use the class as + a type reference.""" + INSTANCE: str PERSISTENCE_CLASS: Optional[str] PERSISTENCE_URI: Optional[str] @@ -22,7 +25,7 @@ class SilverbackIdent(BaseModel): network_choice: str @classmethod - def from_settings(cls, settings_: SilverbackSettings) -> Self: + def from_settings(cls, settings_: ISilverbackSettings) -> Self: return cls(identifier=settings_.INSTANCE, network_choice=settings_.get_network_choice()) diff --git a/silverback/utils.py b/silverback/utils.py index 43da7efd..2a6846e2 100644 --- a/silverback/utils.py +++ b/silverback/utils.py @@ -39,6 +39,7 @@ def iter_to_queue(): def hexbytes_dict(data: dict) -> dict: + """Converts any hex string values in a flat dictionary to HexBytes.""" fixed_data = {} for name, value in data.items():