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
Functions¶
load
async
¶
Load state from JSON file.
Automatically detects and recovers zombie jobs (RUNNING status but process dead). When a zombie is detected, the state is updated to PAUSED and saved before returning.
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.