Skip to content

boxmot.attributes.spool

PostgreSQL crop scheduling and persistent results for attribute extraction.

AttributeSpool

AttributeSpool(
    config: AttributeConfig,
    run_id: str,
    *,
    ownership: CameraLease | None = None,
    max_pending_jobs: int = 1000,
    max_crop_bytes: int = 256 * 1024 * 1024,
)

Serialize PostgreSQL transactions across one run's caller and worker.

Runs share a schema, but every operation is scoped to this run. Only the active request and requested result pages enter memory. Completed outcomes and latest values remain in PostgreSQL after closing the connection; this does not resume abandoned jobs or attach additional workers to a run.

config instance-attribute

config = config

max_crop_bytes instance-attribute

max_crop_bytes = max_crop_bytes

max_pending_jobs instance-attribute

max_pending_jobs = max_pending_jobs

ownership instance-attribute

ownership = ownership

pending_count property

pending_count: int

Count this run's pending, running, and retrying requests.

queue_metrics property

queue_metrics: dict[str, int | float]

Return aggregate backlog size and age without loading crop payloads.

run_id instance-attribute

run_id = run_id

stats property

stats: dict[str, int]

Return this run's outcome counts and distinct observed/analyzed tracks.

append

append(
    generation: int,
    track_id: int,
    step: int,
    sample: AttributeSample,
    image: bytes,
) -> None

Persist a sample, coalescing the pending batch without changing its rank.

cancel

cancel() -> None

Record all this run's outstanding batches as cancelled, freeing crops.

claim

claim() -> _Job | None

Atomically claim the oldest ready request in this run.

close

close() -> None

Close the connection without removing stored results or histories.

complete

complete(
    job: _Job,
    *,
    values: dict[str, Any] | None = None,
    error: str | None = None,
) -> None

Atomically retain an outcome and release the completed job's crops.

flush

flush(
    generation: int | None = None,
    *,
    departed_at: int | None = None,
) -> None

Release partial batches, recording tracks that never supplied a crop.

latest

latest(
    generation: int, track_ids: list[int]
) -> dict[int, AttributeResult]

Read detached snapshots for only this run's current track rows.

observe

observe(
    generation: int,
    sequence_id: str | None,
    track_id: int,
    class_id: int,
    step: int,
    sample: AttributeSample,
) -> int | None

Record a visible identity and return its most recent sampling step.

poll

poll(limit: int) -> list[AttributeResult]

Mark a bounded event page delivered while retaining its history.

retry

retry(job: _Job, delay: float) -> None

Schedule a retry using the database clock without releasing samples.

transaction

transaction() -> Iterator[None]

Batch a frame's writes into one transaction, sanitizing database errors.