Skip to content

Commit

Permalink
add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
kicksent committed Feb 5, 2025
1 parent 78f5d4f commit 089103d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions burr/integrations/persisters/b_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,19 @@ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:
def load(
self, partition_key: Optional[str], app_id: str, sequence_id: int = None, **kwargs
) -> Optional[persistence.PersistedStateData]:
"""Load the state data for a given partition key, app id, and sequence id."""
"""Loads the state data for a given partition key, app_id, and sequence_id.
This method retrieves the most recent state data for the specified (partition_key, app_id) combination.
If a sequence ID is provided, it will attempt to fetch the specific state at that sequence.
:param partition_key: The partition key. Defaults to `None`. **Note:** The partition key defaults to `None`. If a partition key was used during saving, it must be provided
consistently during retrieval, or no results will be returned.
:param app_id: Application UID to read from.
:param sequence_id: (Optional) The sequence ID to retrieve a specific state. If not provided,
the latest state is returned.
:returns: The state data if found, otherwise None.
"""
query = {"partition_key": partition_key, "app_id": app_id}
if sequence_id is not None:
query["sequence_id"] = sequence_id
Expand Down Expand Up @@ -126,7 +138,19 @@ def save(
status: Literal["completed", "failed"],
**kwargs,
):
"""Save the state data to the MongoDB database."""
"""Save the state data to the MongoDB database.
:param partition_key: the partition key. Note this could be None, but it's up to the persistor to whether
that is a valid value it can handle. If a partition key was used during saving, it must be provided
consistently during retrieval, or no results will be returned.
:param app_id: Application UID to write with.
:param sequence_id: Sequence ID of the last executed step.
:param position: The action name that was implemented.
:param state: The current state of the application.
:param status: The status of this state, either "completed" or "failed". If "failed", the state is what it was
before the action was applied.
:return:
"""
key = {"partition_key": partition_key, "app_id": app_id, "sequence_id": sequence_id}
if self.collection.find_one(key):
raise ValueError(f"partition_key:app_id:sequence_id[{key}] already exists.")
Expand Down

0 comments on commit 089103d

Please sign in to comment.