StateBackend adapter that reads job state from the running daemon via IPC.
Wraps DaemonClient to satisfy the StateBackend ABC so the dashboard
can consume live daemon data without touching the filesystem directly.
All write methods raise NotImplementedError — the dashboard is read-only.
Classes
DaemonStateAdapter
DaemonStateAdapter(client)
Bases: StateBackend
Read-only StateBackend backed by live daemon IPC calls.
Parameters
client:
An already-configured DaemonClient instance.
Source code in src/marianne/dashboard/state/daemon_adapter.py
| def __init__(self, client: DaemonClient) -> None:
self._client = client
self._dashboard_metadata: dict[str, dict[str, object]] = {}
|
Methods:
load
async
Load state for a job from the daemon.
Returns None if the job is not found (DaemonError).
Source code in src/marianne/dashboard/state/daemon_adapter.py
| async def load(self, job_id: str) -> CheckpointState | None:
"""Load state for a job from the daemon.
Returns ``None`` if the job is not found (``DaemonError``).
"""
try:
data = await asyncio.wait_for(
self._client.get_job_status(job_id, ""),
timeout=DAEMON_STATE_READ_TIMEOUT_SECONDS,
)
self._dashboard_metadata[job_id] = {
"data_source": "daemon_status",
"is_partial": False,
}
return CheckpointState(**data)
except (DaemonError, ConnectionError, TimeoutError, OSError):
_logger.debug("load_job_not_found", job_id=job_id)
return None
|
list_jobs
async
List all jobs by querying the daemon roster then enriching each.
Source code in src/marianne/dashboard/state/daemon_adapter.py
| async def list_jobs(self) -> list[CheckpointState]:
"""List all jobs by querying the daemon roster then enriching each."""
try:
roster: list[dict[str, Any]] = await asyncio.wait_for(
self._client.list_jobs(),
timeout=DAEMON_STATE_READ_TIMEOUT_SECONDS,
)
except (DaemonError, ConnectionError, TimeoutError, OSError) as exc:
_logger.warning("list_jobs_daemon_unavailable", error_type=type(exc).__name__)
raise DaemonError("Conductor job roster is unavailable; job status is unknown") from exc
if not isinstance(roster, list):
raise DaemonError("Conductor returned an invalid job roster; job status is unknown")
results: list[CheckpointState] = []
for index, entry in enumerate(roster):
job_id = entry.get("job_id", "")
if index < DAEMON_STATE_MAX_ENRICHED_JOBS:
try:
data = await asyncio.wait_for(
self._client.get_job_status(job_id, ""),
timeout=DAEMON_STATE_ENRICH_TIMEOUT_SECONDS,
)
self._dashboard_metadata[job_id] = {
"data_source": "daemon_status",
"is_partial": False,
}
results.append(CheckpointState(**data))
continue
except (DaemonError, ConnectionError, TimeoutError, OSError):
_logger.debug("list_jobs_fallback", job_id=job_id)
reason = (
"enrichment_cap"
if index >= DAEMON_STATE_MAX_ENRICHED_JOBS
else "enrichment_failed"
)
self._dashboard_metadata[job_id] = {
"data_source": "daemon_roster",
"is_partial": True,
"partial_reason": reason,
}
results.append(_checkpoint_from_roster_entry(entry))
return results
|
dashboard_metadata(job_id)
Return source/completeness metadata for the latest dashboard read.
Source code in src/marianne/dashboard/state/daemon_adapter.py
| def dashboard_metadata(self, job_id: str) -> dict[str, object]:
"""Return source/completeness metadata for the latest dashboard read."""
return dict(
self._dashboard_metadata.get(
job_id,
{"data_source": "daemon", "is_partial": True, "partial_reason": "unknown"},
)
)
|
close
async
Release the client connection pool when the backend is closed.
Source code in src/marianne/dashboard/state/daemon_adapter.py
| async def close(self) -> None:
"""Release the client connection pool when the backend is closed."""
await self._client.close()
|
Functions: