soev for developers

warren.storage.jobs

Jobs: the job store, which holds what a job is and its completion status.

Classes

MemoryJobStore

classMemoryJobStore(*, name=None, scoping_enabled=False)

Job definitions and high-level status held in a dict.

Record shape, job id format and error types match MongoDBJobStore so callers cannot tell the two apart. Single-process, gone at exit.

paramnamestr | None
= None
paramscoping_enabledbool
= False
methodsetupasync () -> None

Nothing to create; present because the Protocol requires it.

methodcreate_jobasync (final_data_type, parameters=None, num_documents=None, metadata=None, scope=None) -> str
paramfinal_data_typestr
paramparametersdict | None
= None
paramnum_documentsint | None
= None
parammetadatadict | None
= None
paramscopestr | None
= None
methodget_jobasync (job_id) -> dict
paramjob_idstr
methodupdate_num_documentsasync (job_id, num_documents) -> None
paramjob_idstr
paramnum_documentsint
methodincrement_num_documentsasync (job_id, count=1) -> int
paramjob_idstr
paramcountint
= 1
methodupdate_completionasync (job_id, completed, with_failures) -> bool
paramjob_idstr
paramcompletedbool
paramwith_failuresbool
methodget_statusasync (job_id) -> dict
paramjob_idstr
methodupdate_vector_db_stateasync (job_id, fields) -> None
paramjob_idstr
paramfieldsdict

MongoDBJobStore

classMongoDBJobStore(client, *, database_name, collection_name='jobs', job_records_ttl_seconds=None, job_records_max_age_seconds=None, name=None, scoping_enabled=False)

Async MongoDB implementation of JobStoreInterface.

Stores job definitions and high-level status in a jobs collection. Uses job_id as the unique key.

Requires calling await setup() after construction to create indexes.

paramclientAsyncMongoClient
paramdatabase_namestr
paramcollection_namestr
= 'jobs'
paramjob_records_ttl_secondsint | None
= None

TTL on status.completed_at: a job record is deleted this many seconds after completion. Must be positive. None: the index stays as it is (no TTL by default).

paramjob_records_max_age_secondsint | None
= None

TTL on created_at: a job record is deleted this many seconds after creation. Must be positive. None: the index stays as it is (no TTL by default).

paramnamestr | None
= None
paramscoping_enabledbool
= False

Store the scope on each job in a scope field, and index that field.

methodsetupasync () -> None

Create job identity and retention indexes.

methodcreate_jobasync (final_data_type, parameters=None, num_documents=None, metadata=None, scope=None) -> str
paramfinal_data_typestr
paramparametersdict | None
= None
paramnum_documentsint | None
= None
parammetadatadict | None
= None
paramscopestr | None
= None
methodget_jobasync (job_id) -> dict
paramjob_idstr
methodupdate_num_documentsasync (job_id, num_documents) -> None
paramjob_idstr
paramnum_documentsint
methodincrement_num_documentsasync (job_id, count=1) -> int
paramjob_idstr
paramcountint
= 1
methodupdate_completionasync (job_id, completed, with_failures) -> bool
paramjob_idstr
paramcompletedbool
paramwith_failuresbool
methodget_statusasync (job_id) -> dict
paramjob_idstr
methodupdate_vector_db_stateasync (job_id, fields) -> None
paramjob_idstr
paramfieldsdict

Protocols

JobStoreInterface

protocolJobStoreInterface

Storage protocol for job definitions and job-level status.

Transient-error contract: transient backend failures (connection blips, failover) are raised as warren.storage.TransientStoreError; permanent failures propagate as other exceptions. Callers that cannot tolerate a dropped operation — notably the JobStatusWorker observer, where a lost completion update strands a job — should retry on TransientStoreError.

methodsetupasync () -> None

Create indexes and prepare the store for use.

methodcreate_jobasync (final_data_type, parameters=None, num_documents=None, metadata=None, scope=None) -> str

Create a new job entry with a store-generated ID.

paramfinal_data_typestr

The data_type that marks a document as fully processed (e.g., "final_stage").

paramparametersdict | None
= None

Processing parameters for workers.

paramnum_documentsint | None
= None

Total document count, if known upfront. Can be set later via update_num_documents.

parammetadatadict | None
= None

Optional application-defined metadata.

paramscopestr | None
= None

Scope to store on the job; None uses the current handler scope. Ignored when scoping is off or the scope is not valid.

Returns

str

The generated job ID.

Raises:

  • JobCreationFailedError: If the store cannot create the job.
methodget_jobasync (job_id) -> dict

Get the full job document.

paramjob_idstr

Returns

dict

Job document as dict with all fields.

Raises:

  • JobNotFoundError: If job_id does not exist.
methodupdate_num_documentsasync (job_id, num_documents) -> None

Set or update the number of documents for a job.

A value of 0 means "no documents were successfully submitted" — different from None, which means "not yet known."

paramjob_idstr
paramnum_documentsint

Raises:

  • JobNotFoundError: If job_id does not exist.
methodincrement_num_documentsasync (job_id, count=1) -> int

Atomically increment num_documents and return the new value.

Used when documents are published in batches or streamed, and the total is not known upfront.

paramjob_idstr
paramcountint
= 1

Returns

int

New num_documents value after increment.

Raises:

  • JobNotFoundError: If job_id does not exist.
methodupdate_completionasync (job_id, completed, with_failures) -> bool

Update an unfinished job; return whether this call applied the update.

A completion timestamp prevents later updates, including reopening.

paramjob_idstr
paramcompletedbool
paramwith_failuresbool

Raises:

  • JobNotFoundError: If job_id does not exist.
methodget_statusasync (job_id) -> dict

Get the job's current status.

paramjob_idstr

Returns

dict

Dict with {completed, with_failures, completed_at}.

Raises:

  • JobNotFoundError: If job_id does not exist.
methodupdate_vector_db_stateasync (job_id, fields) -> None

Partially update the job's vector_db sub-document.

A worker that tracks per-job external state uses it to record state transitions. Idempotent — repeated calls with the same fields are safe.

paramjob_idstr

Job to update.

paramfieldsdict

Keys inside the vector_db sub-document, without a prefix, and their values. E.g. {"status": "ready"}. An empty mapping does nothing.

Raises:

  • JobNotFoundError: If job_id does not exist.

Errors

JobCreationFailedError

errorJobCreationFailedError

The store failed to create the job.

JobNotFoundError

errorJobNotFoundError

On this page