nodestep.state.integrations.filesystem ¶
FilesystemStateStore, which keeps each thread's history in a JSON Lines file.
See State stores.
FilesystemStateStore¶
FilesystemStateStore(path)
State store that appends history to a JSON Lines file.
Subclass of InMemoryStateStore.
Processes can share the file. See State stores for its header record, its lock and the repair of an interrupted write.
path | str | Path |
Store file; missing parent directories are created. |
StateStoreError |
If the runtime has no file lock, |
repaired_bytes | int |
Bytes truncated by the last repair, or |
Methods
async append_event(event)¶
Store an event as given.
async append_event(event)¶async append_event(event) -> HistoryEvent
event | HistoryEvent | |
HistoryEvent |
The same event. |
StateStoreError |
If a record another writer appended to the file is corrupt. |
async append_next_event(event)¶
Store an event with the next sequence number of its thread.
async append_next_event(event)¶async append_next_event(event) -> HistoryEvent
event | HistoryEvent |
Event whose |
HistoryEvent |
The stored event with its sequence number. |
StateStoreError |
If a record another writer appended to the file is corrupt. |
async save_checkpoint(checkpoint)¶
Store a state snapshot.
async save_checkpoint(checkpoint)¶async save_checkpoint(checkpoint) -> CheckpointRecord
checkpoint | CheckpointRecord | |
CheckpointRecord |
The same checkpoint. |
StateStoreError |
If a record another writer appended to the file is corrupt. |
async fork(thread_id, ...)¶
Record a new branch starting at an event.
async fork(thread_id, ...)¶async fork(thread_id, *, from_, branch_id='main', name=None) -> BranchRecord
thread_id | str | |
from_ | str |
Event id to branch from. |
branch_id | str |
Branch to fork; |
name | str | None |
Id of the new branch; a random id when omitted. |
StateStoreError |
If the thread already has a branch with that id, including
|
async list_branches(thread_id)¶
Return the branches forked from a thread, oldest first.
async list_branches(thread_id)¶async list_branches(thread_id) -> list[BranchRecord]
thread_id | str | |
list[BranchRecord] |
Every recorded fork of the thread; |
StateStoreError |
If a record another writer appended to the file is corrupt. |
async get_history(thread_id, branch_id)¶
Return the events and checkpoints of a thread branch.
async get_history(thread_id, branch_id)¶async get_history(thread_id, branch_id='main') -> History
thread_id | str | |
branch_id | str |
Branch to read; |
History |
Empty lists for a thread or branch the store does not know. |
StateStoreError |
If a record another writer appended to the file is corrupt. |
async latest_checkpoint(thread_id, branch_id, at)¶
Return the latest checkpoint, optionally at or before an event.
async latest_checkpoint(thread_id, branch_id, at)¶async latest_checkpoint(thread_id, branch_id='main', at=None) -> CheckpointRecord | None
thread_id | str | |
branch_id | str |
Branch to read; |
at | str | None |
Event id; only checkpoints up to that event count. |
CheckpointRecord or None |
|
StateUpdateError |
If |
StateStoreError |
If a record another writer appended to the file is corrupt. |