Skip to content

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.

Attributes

TERMINAL_DAEMON_JOB_STATUSES module-attribute

TERMINAL_DAEMON_JOB_STATUSES = frozenset({DaemonJobStatus.COMPLETED, DaemonJobStatus.FAILED, DaemonJobStatus.CANCELLED})

The daemon job-level terminal set — the single definition (GH #225).

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.

Attributes
is_terminal property
is_terminal

Whether the job has finished (completed, failed, or cancelled).

Mirrors JobStatus.is_terminal; both enums share the same three terminal members by name. TERMINAL_DAEMON_JOB_STATUSES is the one set every consumer reads (GH #225).

FailureHooksInProgressError

Bases: RuntimeError

Raised when a stable job ID still owns an unsettled hook claim.

JobRecord dataclass

JobRecord(job_id, config_path, workspace, status=QUEUED, pid=None, submitted_at=time(), running_seconds=0.0, 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, max_wall_seconds=None, wall_deadline_at=None, terminal_reason=None, deadline_diagnostic=None, failure_hooks_started_at=None, failure_hooks_completed_at=None, chain_depth=None)

A single job's registry entry.

Methods:
to_dict
to_dict()

Serialize for JSON-RPC responses.

Source code in src/marianne/daemon/registry.py
def to_dict(self) -> dict[str, Any]:
    """Serialize for JSON-RPC responses."""
    result: dict[str, Any] = {
        "job_id": self.job_id,
        "config_path": self.config_path,
        "workspace": self.workspace,
        "status": self.status,
        "pid": self.pid,
        "submitted_at": self.submitted_at,
        "running_seconds": self.running_seconds,
        "started_at": self.started_at,
        "completed_at": self.completed_at,
        "current_sheet": self.current_sheet,
        "total_sheets": self.total_sheets,
    }
    if self.error_message:
        result["error_message"] = self.error_message
    if self.log_path:
        result["log_path"] = self.log_path
    if self.snapshot_path:
        result["snapshot_path"] = self.snapshot_path
    if self.max_wall_seconds is not None:
        result["max_wall_seconds"] = self.max_wall_seconds
    if self.wall_deadline_at is not None:
        result["wall_deadline_at"] = self.wall_deadline_at
    if self.terminal_reason is not None:
        result["terminal_reason"] = self.terminal_reason
    return result

JobRegistry

JobRegistry(db_path, *, busy_timeout_seconds=None)

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
def __init__(
    self, db_path: Path, *, busy_timeout_seconds: float | None = None,
) -> None:
    self._db_path = db_path
    db_path.parent.mkdir(parents=True, exist_ok=True)
    self._conn: aiosqlite.Connection | None = None
    timeout = (
        self.DEFAULT_BUSY_TIMEOUT_SECONDS
        if busy_timeout_seconds is None
        else busy_timeout_seconds
    )
    if not math.isfinite(timeout) or timeout <= 0:
        raise ValueError("busy_timeout_seconds must be a positive finite duration")
    self._busy_timeout_seconds = timeout
Methods:
open async
open()

Open the database connection and create tables.

Source code in src/marianne/daemon/registry.py
async def open(self) -> None:
    """Open the database connection and create tables."""
    conn = await aiosqlite.connect(
        str(self._db_path), timeout=self._busy_timeout_seconds,
    )
    try:
        conn.row_factory = aiosqlite.Row
        await conn.execute("PRAGMA journal_mode=WAL")
        await conn.execute(
            f"PRAGMA busy_timeout={int(self._busy_timeout_seconds * 1000)}"
        )
        await self._create_tables(conn)
    except Exception:
        await conn.close()
        raise
    self._conn = conn
    _logger.info("registry.opened", path=str(self._db_path))
register_job async
register_job(job_id, config_path, workspace, log_path=None, *, submitted_at=None, max_wall_seconds=None, wall_deadline_at=None, concert_config_json=None, chain_depth=None)

Commit and return one newly submitted execution authority.

Source code in src/marianne/daemon/registry.py
async def register_job(
    self,
    job_id: str,
    config_path: Path,
    workspace: Path,
    log_path: Path | None = None,
    *,
    submitted_at: float | None = None,
    max_wall_seconds: float | None = None,
    wall_deadline_at: float | None = None,
    concert_config_json: str | None = None,
    chain_depth: int | None = None,
) -> JobRecord:
    """Commit and return one newly submitted execution authority."""
    registered_at = time.time() if submitted_at is None else submitted_at
    if not math.isfinite(registered_at):
        raise ValueError("submitted_at must be finite")
    if max_wall_seconds is not None:
        if not math.isfinite(max_wall_seconds) or max_wall_seconds <= 0:
            raise ValueError("max_wall_seconds must be finite and positive")
        if wall_deadline_at is None:
            wall_deadline_at = registered_at + max_wall_seconds
    if wall_deadline_at is not None and (
        not math.isfinite(wall_deadline_at) or wall_deadline_at <= 0
    ):
        raise ValueError("wall_deadline_at must be finite and positive")
    # Reaching this seam means manager admission accepted a new execution.
    # Continuations never call register_job; an accepted stable-ID rerun
    # intentionally replaces the prior execution authority atomically.
    cursor = await self._db.execute(
        """
        INSERT INTO jobs
            (job_id, config_path, workspace, status, submitted_at, log_path,
             max_wall_seconds, wall_deadline_at, terminal_reason,
             concert_config_json, chain_depth)
        VALUES (?, ?, ?, 'queued', ?, ?, ?, ?, NULL, ?, ?)
        ON CONFLICT(job_id) DO UPDATE SET
            config_path = excluded.config_path,
            workspace = excluded.workspace,
            status = 'queued',
            pid = NULL,
            started_at = NULL,
            completed_at = NULL,
            error_message = NULL,
            current_sheet = NULL,
            total_sheets = NULL,
            last_event_at = NULL,
            log_path = excluded.log_path,
            snapshot_path = NULL,
            checkpoint_json = NULL,
            hook_config_json = NULL,
            hook_results_json = NULL,
            failure_hook_config_json = NULL,
            failure_hook_results_json = NULL,
            failure_hooks_started_at = NULL,
            failure_hooks_completed_at = NULL,
            concert_config_json = excluded.concert_config_json,
            chain_depth = excluded.chain_depth,
            submitted_at = excluded.submitted_at,
            running_seconds = 0,
            max_wall_seconds = excluded.max_wall_seconds,
            wall_deadline_at = excluded.wall_deadline_at,
            terminal_reason = NULL
        WHERE jobs.failure_hooks_started_at IS NULL
           OR jobs.failure_hooks_completed_at IS NOT NULL
        """,
        (
            job_id,
            str(config_path),
            str(workspace),
            registered_at,
            str(log_path) if log_path is not None else None,
            max_wall_seconds,
            wall_deadline_at,
            concert_config_json,
            chain_depth,
        ),
    )
    if cursor.rowcount != 1:
        await self._db.rollback()
        raise FailureHooksInProgressError(
            f"Job '{job_id}' is still running terminal failure hooks"
        )
    await self._db.commit()
    committed = await self.get_job(job_id)
    if committed is None:
        raise RuntimeError(f"registered job '{job_id}' was not readable")
    return committed
update_status async
update_status(job_id, status, *, pid=None, error_message=None, snapshot_path=None, terminal_reason=None, running_seconds=None)

Update a job's status and optional fields in the registry only.

Breadcrumb (#263): this writes ONLY the registry row. It does NOT touch the daemon's in-memory _job_meta / _live_states, so calling it directly for a live job diverges mzt list from mzt status. Status changes for live jobs MUST go through JobManager._set_job_status (the three-store update). Direct use is reserved for paths with no in-memory state (startup orphan recovery, task-creation-failure cleanup) or registry/live reconciliation (shutdown flush) — see test_set_job_status_guard_263 for the enforced allow-list.

Source code in src/marianne/daemon/registry.py
async def update_status(
    self,
    job_id: str,
    status: str,
    *,
    pid: int | None = None,
    error_message: str | None = None,
    snapshot_path: str | None = None,
    terminal_reason: str | None = None,
    running_seconds: float | None = None,
) -> None:
    """Update a job's status and optional fields in the registry only.

    Breadcrumb (#263): this writes ONLY the registry row. It does NOT touch
    the daemon's in-memory ``_job_meta`` / ``_live_states``, so calling it
    directly for a live job diverges ``mzt list`` from ``mzt status``.
    Status changes for live jobs MUST go through
    ``JobManager._set_job_status`` (the three-store update). Direct use is
    reserved for paths with no in-memory state (startup orphan recovery,
    task-creation-failure cleanup) or registry/live reconciliation
    (shutdown flush) — see ``test_set_job_status_guard_263`` for the
    enforced allow-list.
    """
    updates = ["status = ?"]
    params: list[Any] = [status]
    if running_seconds is not None:
        if not math.isfinite(running_seconds) or running_seconds < 0:
            raise ValueError("running_seconds must be finite and non-negative")
        updates.append("running_seconds = ?")
        params.append(running_seconds)

    if pid is not None:
        updates.append("pid = ?")
        params.append(pid)

    if status == "running" and pid is not None:
        updates.append("started_at = ?")
        params.append(time.time())

    if status in _TERMINAL_STATUSES:
        updates.append("completed_at = ?")
        params.append(time.time())

    if error_message is not None:
        updates.append("error_message = ?")
        params.append(error_message)

    if snapshot_path is not None:
        updates.append("snapshot_path = ?")
        params.append(snapshot_path)

    if status not in _TERMINAL_STATUSES:
        updates.append("terminal_reason = NULL")
    elif terminal_reason is not None:
        updates.append("terminal_reason = ?")
        params.append(terminal_reason)

    params.append(job_id)
    await self._db.execute(
        f"UPDATE jobs SET {', '.join(updates)} WHERE job_id = ?",
        params,
    )
    await self._db.commit()
update_config_metadata async
update_config_metadata(job_id, *, config_path=None, workspace=None)

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
async def update_config_metadata(
    self,
    job_id: str,
    *,
    config_path: str | None = None,
    workspace: str | None = None,
) -> None:
    """Update config-derived metadata for a job.

    Called during config reconciliation to keep registry in sync
    with the reloaded config.
    """
    updates: list[str] = []
    params: list[Any] = []

    if config_path is not None:
        updates.append("config_path = ?")
        params.append(config_path)
    if workspace is not None:
        updates.append("workspace = ?")
        params.append(workspace)

    if not updates:
        return

    params.append(job_id)
    await self._db.execute(
        f"UPDATE jobs SET {', '.join(updates)} WHERE job_id = ?",
        params,
    )
    await self._db.commit()
update_progress async
update_progress(job_id, current_sheet, total_sheets)

Update per-sheet progress counters for a running job.

Source code in src/marianne/daemon/registry.py
async def update_progress(
    self,
    job_id: str,
    current_sheet: int,
    total_sheets: int,
) -> None:
    """Update per-sheet progress counters for a running job."""
    await self._db.execute(
        "UPDATE jobs SET current_sheet = ?, total_sheets = ?, "
        "last_event_at = ? WHERE job_id = ?",
        (current_sheet, total_sheets, time.time(), job_id),
    )
    await self._db.commit()
save_checkpoint async
save_checkpoint(job_id, checkpoint_json)

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
async def save_checkpoint(self, job_id: str, checkpoint_json: str) -> None:
    """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.
    """
    await self._db.execute(
        "UPDATE jobs SET checkpoint_json = ?, last_event_at = ? "
        "WHERE job_id = ?",
        (checkpoint_json, time.time(), job_id),
    )
    await self._db.commit()
load_checkpoint async
load_checkpoint(job_id)

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
async def load_checkpoint(self, job_id: str) -> str | None:
    """Load the stored checkpoint JSON for a job.

    Returns the raw JSON string, or None if no checkpoint was saved.
    """
    cursor = await self._db.execute(
        "SELECT checkpoint_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["checkpoint_json"]
    return result
store_hook_config async
store_hook_config(job_id, config_json)

Store hook configuration for a job at submission time.

Source code in src/marianne/daemon/registry.py
async def store_hook_config(self, job_id: str, config_json: str) -> None:
    """Store hook configuration for a job at submission time."""
    await self._db.execute(
        "UPDATE jobs SET hook_config_json = ? WHERE job_id = ?",
        (config_json, job_id),
    )
    await self._db.commit()
get_hook_config async
get_hook_config(job_id)

Load stored hook config JSON for a job.

Source code in src/marianne/daemon/registry.py
async def get_hook_config(self, job_id: str) -> str | None:
    """Load stored hook config JSON for a job."""
    cursor = await self._db.execute(
        "SELECT hook_config_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["hook_config_json"]
    return result
store_hook_results async
store_hook_results(job_id, results_json)

Store hook execution results for a job.

Source code in src/marianne/daemon/registry.py
async def store_hook_results(self, job_id: str, results_json: str) -> None:
    """Store hook execution results for a job."""
    await self._db.execute(
        "UPDATE jobs SET hook_results_json = ? WHERE job_id = ?",
        (results_json, job_id),
    )
    await self._db.commit()
get_hook_results async
get_hook_results(job_id)

Load stored hook execution results JSON for a job.

Source code in src/marianne/daemon/registry.py
async def get_hook_results(self, job_id: str) -> str | None:
    """Load stored hook execution results JSON for a job."""
    cursor = await self._db.execute(
        "SELECT hook_results_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["hook_results_json"]
    return result
store_failure_hook_config async
store_failure_hook_config(job_id, config_json)

Store terminal-failure hook configuration for restart recovery.

Source code in src/marianne/daemon/registry.py
async def store_failure_hook_config(self, job_id: str, config_json: str) -> None:
    """Store terminal-failure hook configuration for restart recovery."""
    await self._db.execute(
        "UPDATE jobs SET failure_hook_config_json = ? WHERE job_id = ?",
        (config_json, job_id),
    )
    await self._db.commit()
get_failure_hook_config async
get_failure_hook_config(job_id)

Load terminal-failure hook configuration for a job.

Source code in src/marianne/daemon/registry.py
async def get_failure_hook_config(self, job_id: str) -> str | None:
    """Load terminal-failure hook configuration for a job."""
    cursor = await self._db.execute(
        "SELECT failure_hook_config_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["failure_hook_config_json"]
    return result
store_concert_config async
store_concert_config(job_id, config_json)

Store concert context used by durable run_job hooks.

Source code in src/marianne/daemon/registry.py
async def store_concert_config(self, job_id: str, config_json: str) -> None:
    """Store concert context used by durable run_job hooks."""
    await self._db.execute(
        "UPDATE jobs SET concert_config_json = ? WHERE job_id = ?",
        (config_json, job_id),
    )
    await self._db.commit()
store_concert_context async
store_concert_context(job_id, config_json, chain_depth)

Persist the concert policy and current depth in one update.

Source code in src/marianne/daemon/registry.py
async def store_concert_context(
    self,
    job_id: str,
    config_json: str | None,
    chain_depth: int | None,
) -> None:
    """Persist the concert policy and current depth in one update."""
    await self._db.execute(
        """
        UPDATE jobs
        SET concert_config_json = ?, chain_depth = ?
        WHERE job_id = ?
        """,
        (config_json, chain_depth, job_id),
    )
    await self._db.commit()
get_concert_config async
get_concert_config(job_id)

Load concert context used by durable run_job hooks.

Source code in src/marianne/daemon/registry.py
async def get_concert_config(self, job_id: str) -> str | None:
    """Load concert context used by durable run_job hooks."""
    cursor = await self._db.execute(
        "SELECT concert_config_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["concert_config_json"]
    return result
store_failure_hook_results async
store_failure_hook_results(job_id, results_json)

Store terminal-failure hook results without replacing job failure data.

Source code in src/marianne/daemon/registry.py
async def store_failure_hook_results(self, job_id: str, results_json: str) -> None:
    """Store terminal-failure hook results without replacing job failure data."""
    await self._db.execute(
        "UPDATE jobs SET failure_hook_results_json = ? WHERE job_id = ?",
        (results_json, job_id),
    )
    await self._db.commit()
get_failure_hook_results async
get_failure_hook_results(job_id)

Load terminal-failure hook results for diagnostics.

Source code in src/marianne/daemon/registry.py
async def get_failure_hook_results(self, job_id: str) -> str | None:
    """Load terminal-failure hook results for diagnostics."""
    cursor = await self._db.execute(
        "SELECT failure_hook_results_json FROM jobs WHERE job_id = ?",
        (job_id,),
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    result: str | None = row["failure_hook_results_json"]
    return result
claim_failure_hooks async
claim_failure_hooks(job_id)

Atomically claim a failed job's hook execution exactly once.

Source code in src/marianne/daemon/registry.py
async def claim_failure_hooks(self, job_id: str) -> bool:
    """Atomically claim a failed job's hook execution exactly once."""
    cursor = await self._db.execute(
        """
        UPDATE jobs
        SET failure_hooks_started_at = ?
        WHERE job_id = ?
          AND status = 'failed'
          AND failure_hook_config_json IS NOT NULL
          AND failure_hooks_started_at IS NULL
        """,
        (time.time(), job_id),
    )
    await self._db.commit()
    return cursor.rowcount == 1
complete_failure_hooks async
complete_failure_hooks(job_id)

Persist completion of a previously claimed failure-hook sequence.

Source code in src/marianne/daemon/registry.py
async def complete_failure_hooks(self, job_id: str) -> None:
    """Persist completion of a previously claimed failure-hook sequence."""
    await self._db.execute(
        """
        UPDATE jobs
        SET failure_hooks_completed_at = ?
        WHERE job_id = ?
          AND failure_hooks_started_at IS NOT NULL
          AND failure_hooks_completed_at IS NULL
        """,
        (time.time(), job_id),
    )
    await self._db.commit()
settle_failure_hooks async
settle_failure_hooks(job_id, results_json)

Atomically record hook results and settle their durable claim.

Source code in src/marianne/daemon/registry.py
async def settle_failure_hooks(self, job_id: str, results_json: str) -> None:
    """Atomically record hook results and settle their durable claim."""
    await self._db.execute(
        """
        UPDATE jobs
        SET failure_hook_results_json = ?, failure_hooks_completed_at = ?
        WHERE job_id = ?
          AND failure_hooks_started_at IS NOT NULL
          AND failure_hooks_completed_at IS NULL
        """,
        (results_json, time.time(), job_id),
    )
    await self._db.commit()
get_job async
get_job(job_id)

Get a single job by ID.

Source code in src/marianne/daemon/registry.py
async def get_job(self, job_id: str) -> JobRecord | None:
    """Get a single job by ID."""
    cursor = await self._db.execute(
        "SELECT * FROM jobs WHERE job_id = ?", (job_id,)
    )
    row = await cursor.fetchone()
    if row is None:
        return None
    return self._row_to_record(row)
list_jobs async
list_jobs(*, status=None, limit=50)

List jobs, most recent first.

Source code in src/marianne/daemon/registry.py
async def list_jobs(
    self,
    *,
    status: str | None = None,
    limit: int = 50,
) -> list[JobRecord]:
    """List jobs, most recent first."""
    if status:
        cursor = await self._db.execute(
            "SELECT * FROM jobs WHERE status = ? ORDER BY submitted_at DESC LIMIT ?",
            (status, limit),
        )
    else:
        cursor = await self._db.execute(
            "SELECT * FROM jobs ORDER BY submitted_at DESC LIMIT ?",
            (limit,),
        )
    rows = await cursor.fetchall()
    return [self._row_to_record(r) for r in rows]
has_active_job async
has_active_job(job_id)

Check if a job ID exists and is in an active state.

Source code in src/marianne/daemon/registry.py
async def has_active_job(self, job_id: str) -> bool:
    """Check if a job ID exists and is in an active state."""
    cursor = await self._db.execute(
        "SELECT 1 FROM jobs WHERE job_id = ? AND status IN ('queued', 'running')",
        (job_id,),
    )
    row = await cursor.fetchone()
    return row is not None
get_orphaned_jobs async
get_orphaned_jobs()

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
async def get_orphaned_jobs(self) -> list[JobRecord]:
    """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.
    """
    cursor = await self._db.execute(
        "SELECT * FROM jobs WHERE status IN ('queued', 'running') "
        "ORDER BY submitted_at DESC"
    )
    rows = await cursor.fetchall()
    return [self._row_to_record(r) for r in rows]
mark_orphans_failed async
mark_orphans_failed()

Mark all orphaned jobs as failed on daemon startup.

Returns the number of jobs marked.

Source code in src/marianne/daemon/registry.py
async def mark_orphans_failed(self) -> int:
    """Mark all orphaned jobs as failed on daemon startup.

    Returns the number of jobs marked.
    """
    cursor = await self._db.execute(
        """
        UPDATE jobs SET
            status = 'failed',
            completed_at = ?,
            error_message = 'Daemon restarted while job was active'
        WHERE status IN ('queued', 'running')
        """,
        (time.time(),),
    )
    await self._db.commit()
    count = cursor.rowcount
    if count > 0:
        _logger.warning("registry.orphans_marked_failed", count=count)
    return count
delete_jobs async
delete_jobs(*, job_ids=None, statuses=None, older_than_seconds=None)

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.

Source code in src/marianne/daemon/registry.py
async def delete_jobs(
    self,
    *,
    job_ids: list[str] | None = None,
    statuses: list[str] | None = None,
    older_than_seconds: float | None = None,
) -> int:
    """Delete terminal jobs from the registry.

    Never deletes active jobs (queued/running) regardless of filter.

    Args:
        job_ids: Only delete these specific job IDs.
        statuses: Only delete jobs with these statuses.
                  Defaults to all terminal statuses.
        older_than_seconds: Only delete jobs older than this many seconds.

    Returns:
        Number of deleted rows.
    """
    safe = set(statuses or _TERMINAL_STATUSES)
    safe -= _ACTIVE_STATUSES

    conditions = ["status IN ({})".format(",".join("?" for _ in safe))]
    params: list[Any] = list(safe)

    if job_ids is not None:
        conditions.append(
            "job_id IN ({})".format(",".join("?" for _ in job_ids))
        )
        params.extend(job_ids)

    if older_than_seconds is not None:
        conditions.append("submitted_at < ?")
        params.append(time.time() - older_than_seconds)

    sql = "DELETE FROM jobs WHERE " + " AND ".join(conditions)
    cursor = await self._db.execute(sql, params)
    await self._db.commit()
    count = cursor.rowcount
    if count > 0:
        _logger.info("registry.delete_jobs", deleted=count)
    return count
close async
close()

Close the database connection.

Source code in src/marianne/daemon/registry.py
async def close(self) -> None:
    """Close the database connection."""
    if self._conn is not None:
        await self._conn.close()
        self._conn = None

Functions: