json_backend
json_backend
¶
JSON file-based state backend.
Simple state storage using JSON files, similar to the .review-state approach in the original bash script.
Classes¶
StateCorruptionError
¶
Bases: Exception
Raised when a state file exists but contains corrupt or invalid data.
Distinguishes corrupt state (data loss) from missing state (normal for new jobs).
Source code in src/marianne/state/json_backend.py
JsonStateBackend
¶
Bases: StateBackend
JSON file-based state storage.
Stores each job's state in a separate JSON file within the state directory. File naming: {state_dir}/{job_id}.json
Initialize JSON backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dir
|
Path
|
Directory to store state files |
required |
Source code in src/marianne/state/json_backend.py
Methods:¶
load
async
¶
Load state from JSON file.
Detects zombie jobs (RUNNING status but process dead) and marks the
returned in-memory state accordingly, but does NOT persist — load()
is read-only so dashboard/CLI callers don't mutate stored state. Callers
that need the zombie transition persisted (e.g. the runner lifecycle)
save explicitly. (#244: the prior docstring wrongly claimed it saved.)
Source code in src/marianne/state/json_backend.py
save
async
¶
Save state to JSON file.
Source code in src/marianne/state/json_backend.py
delete
async
¶
list_jobs
async
¶
List all jobs with state files.
Optimized: reads raw JSON and sorts by updated_at before doing full Pydantic validation, avoiding expensive model_validate on every file just to determine sort order.
Source code in src/marianne/state/json_backend.py
get_next_sheet
async
¶
Get next sheet from state.
mark_sheet_status
async
¶
Update sheet status in state.
The load-modify-save sequence is serialized by _mutate_lock so
concurrent updates to different sheets of the same job cannot lose each
other's changes (#221).