basic_bot.commons.persist_state
PersistState Objects
Class to handle persisting the bot state to a file.
__init__
Initialize the PersistState object and load the persisted state from the file if it exists.
Arguments:
- hub_state: the hub state object instance to persist
- file_path: the file path to persist the state to
- persisted_state_keys: the keys to persist to the file
Usage:
from basic_bot.commons.hub_state import HubState
from basic_bot.commons.persist_state import PersistState
# initialize the hub state
hub_state = HubState({
"test_key": "test_value",
"some_other_key": "some_other_value"
})
# hub_state will be updated with the persisted state if the file exists
persist = PersistState(hub_state, "./my_service_persisted.json", ["test_key"])
# ... do something that updates the hub_state
persist.persist_state()
persist_state
Persist the current state to a file.