registry
registry
¶
Persistent job registry for the Marianne daemon.
SQLite-backed registry that tracks all jobs submitted to the daemon.
Survives daemon restarts so mzt list always shows job history.
Separate from the learning store (which tracks patterns across jobs). This DB tracks operational state: which jobs exist, their workspaces, PIDs, and statuses.
All database methods are async (via aiosqlite) so they never block
the daemon's asyncio event loop — even under heavy concurrent load.
Classes¶
DaemonJobStatus
¶
Bases: str, Enum
Status values for daemon-managed jobs.
Inherits from str so meta.status serializes directly as
a plain string in JSON/dict output — no .value calls needed.
JobRecord
dataclass
¶
JobRecord(job_id, config_path, workspace, status=QUEUED, pid=None, submitted_at=time(), started_at=None, completed_at=None, error_message=None, current_sheet=None, total_sheets=None, last_event_at=None, log_path=None, snapshot_path=None, checkpoint_json=None)
A single job's registry entry.
Functions¶
to_dict
¶
Serialize for JSON-RPC responses.
Source code in src/marianne/daemon/registry.py
JobRegistry
¶
Async SQLite-backed persistent job registry.
Uses aiosqlite so all I/O happens off the event loop thread.
The daemon is single-threaded (asyncio) so contention is minimal,
but the DB is safe for external readers (e.g. a monitoring tool
reading the same file).
Usage::
registry = JobRegistry(db_path)
await registry.open() # creates tables, sets WAL mode
...
await registry.close()
Or as an async context manager::
async with JobRegistry(db_path) as registry:
await registry.register_job(...)
Source code in src/marianne/daemon/registry.py
Functions¶
open
async
¶
Open the database connection and create tables.
Source code in src/marianne/daemon/registry.py
register_job
async
¶
Register a newly submitted job.
Source code in src/marianne/daemon/registry.py
update_status
async
¶
Update a job's status and optional fields.
Source code in src/marianne/daemon/registry.py
update_config_metadata
async
¶
Update config-derived metadata for a job.
Called during config reconciliation to keep registry in sync with the reloaded config.
Source code in src/marianne/daemon/registry.py
update_progress
async
¶
Update per-sheet progress counters for a running job.
Source code in src/marianne/daemon/registry.py
save_checkpoint
async
¶
Persist a serialized CheckpointState for a job.
Called on every state publish so the registry always has the latest checkpoint. This is the daemon's single source of truth for historical job status — no disk fallback needed.
Source code in src/marianne/daemon/registry.py
load_checkpoint
async
¶
Load the stored checkpoint JSON for a job.
Returns the raw JSON string, or None if no checkpoint was saved.
Source code in src/marianne/daemon/registry.py
store_hook_config
async
¶
Store hook configuration for a job at submission time.
Source code in src/marianne/daemon/registry.py
get_hook_config
async
¶
Load stored hook config JSON for a job.
Source code in src/marianne/daemon/registry.py
store_hook_results
async
¶
Store hook execution results for a job.
Source code in src/marianne/daemon/registry.py
get_job
async
¶
Get a single job by ID.
Source code in src/marianne/daemon/registry.py
list_jobs
async
¶
List jobs, most recent first.
Source code in src/marianne/daemon/registry.py
has_active_job
async
¶
Check if a job ID exists and is in an active state.
Source code in src/marianne/daemon/registry.py
get_orphaned_jobs
async
¶
Find jobs that were running when the daemon last stopped.
These are jobs with status 'queued' or 'running' — after a daemon restart they're orphans since their asyncio tasks no longer exist.
Source code in src/marianne/daemon/registry.py
mark_orphans_failed
async
¶
Mark all orphaned jobs as failed on daemon startup.
Returns the number of jobs marked.
Source code in src/marianne/daemon/registry.py
delete_jobs
async
¶
Delete terminal jobs from the registry.
Never deletes active jobs (queued/running) regardless of filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_ids
|
list[str] | None
|
Only delete these specific job IDs. |
None
|
statuses
|
list[str] | None
|
Only delete jobs with these statuses. Defaults to all terminal statuses. |
None
|
older_than_seconds
|
float | None
|
Only delete jobs older than this many seconds. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of deleted rows. |