warren.storage.job_results
Job results: one status record for each document and stage of a job.
Classes
MemoryJobResultsStore
classMemoryJobResultsStore(*, name=None)Per-document, per-stage status ledger held in a dict.
One record per (job_id, data_type, doc_id), the same identity the
Mongo store enforces with its unique index. A record's failure state
is carried by which fields are present: soft_failures (a list of
reasons) or hard_failure (one error string). Recording an outcome
removes the fields that belong to the other outcomes, exactly as the
Mongo store does with $unset.
paramnamestr | None= Nonemethodsetupasync () -> NoneNothing to create; present because the Protocol requires it.
methodrecord_successasync (job_id, data_type, doc_id, origin_type, origin_name) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrmethodrecord_soft_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, retry_count, error_reason) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrparamconsumer_typestrparamconsumer_namestrparamretry_countintparamerror_reasonstrmethodrecord_hard_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, error) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrparamconsumer_typestrparamconsumer_namestrparamerrorstrmethodcount_completed_docsasync (job_id, final_data_type) -> intparamjob_idstrparamfinal_data_typestrmethodcount_hard_failed_docsasync (job_id) -> intparamjob_idstrmethodget_stage_countsasync (job_id) -> list[dict]paramjob_idstrmethodget_doc_statusasync (job_id, doc_id) -> list[dict]paramjob_idstrparamdoc_idstrmethodget_failuresasync (job_id, data_type=None) -> list[dict]paramjob_idstrparamdata_typestr | None= Nonemethodget_unique_errorsasync (job_id, data_type=None) -> list[dict]paramjob_idstrparamdata_typestr | None= NoneMongoDBJobResultsStore
classMongoDBJobResultsStore(client, *, database_name, collection_name='job_results', job_records_ttl_seconds=None, name=None, scoping_enabled=False)Async MongoDB implementation of JobResultsStoreInterface.
Stores per-document processing results in a job_results
collection. Each record is keyed by (job_id, data_type, doc_id)
via a unique composite index, enabling atomic upsert operations.
Requires calling await setup() after construction to create
indexes.
paramclientAsyncMongoClientparamdatabase_namestrparamcollection_namestr= 'job_results'paramjob_records_ttl_secondsint | None= NoneTTL on time: a record is deleted this many seconds after its last write. Must be positive. None: the index stays as it is (no TTL by default).
paramnamestr | None= Noneparamscoping_enabledbool= FalseStore the scope of the current handler on each record in a scope field, and index that field.
methodsetupasync () -> NoneCreate indexes for the job_results collection.
methodrecord_successasync (job_id, data_type, doc_id, origin_type, origin_name) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrmethodrecord_soft_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, retry_count, error_reason) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrparamconsumer_typestrparamconsumer_namestrparamretry_countintparamerror_reasonstrmethodrecord_hard_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, error) -> Noneparamjob_idstrparamdata_typestrparamdoc_idstrparamorigin_typestrparamorigin_namestrparamconsumer_typestrparamconsumer_namestrparamerrorstrmethodcount_completed_docsasync (job_id, final_data_type) -> intparamjob_idstrparamfinal_data_typestrmethodcount_hard_failed_docsasync (job_id) -> intparamjob_idstrmethodget_stage_countsasync (job_id) -> list[dict]paramjob_idstrmethodget_doc_statusasync (job_id, doc_id) -> list[dict]paramjob_idstrparamdoc_idstrmethodget_failuresasync (job_id, data_type=None) -> list[dict]paramjob_idstrparamdata_typestr | None= Nonemethodget_unique_errorsasync (job_id, data_type=None) -> list[dict]paramjob_idstrparamdata_typestr | None= NoneProtocols
JobResultsStoreInterface
protocolJobResultsStoreInterfaceStorage protocol for per-document processing results.
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 write strands a job —
should retry on TransientStoreError.
methodsetupasync () -> NoneCreate indexes and prepare the store for use.
methodrecord_successasync (job_id, data_type, doc_id, origin_type, origin_name) -> NoneRecord a successful processing result.
Upserts the (job_id, data_type, doc_id) record. If the
record previously held a failure (soft or hard), it is overwritten
with success and failure-specific fields are cleared.
paramjob_idstrJob ID. Part of the record key.
paramdata_typestrThe pipeline stage. Part of the record key.
paramdoc_idstrDocument ID. Part of the record key.
paramorigin_typestrWho produced the message.
paramorigin_namestrName of the producer.
methodrecord_soft_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, retry_count, error_reason) -> NoneRecord a soft (retryable) failure.
Upserts the (job_id, data_type, doc_id) record. Appends
error_reason to the soft_failures list so the full
retry history is preserved.
paramjob_idstrJob ID. Part of the record key.
paramdata_typestrThe pipeline stage. Part of the record key.
paramdoc_idstrDocument ID. Part of the record key.
paramorigin_typestrWho produced the message that failed.
paramorigin_namestrName of the producer.
paramconsumer_typestrWho failed to consume it.
paramconsumer_namestrName of the consumer.
paramretry_countintNumber of retries so far. Replaces the stored value.
paramerror_reasonstrReason for this failure.
methodrecord_hard_failureasync (job_id, data_type, doc_id, origin_type, origin_name, consumer_type, consumer_name, error) -> NoneRecord a hard (permanent) failure.
Upserts the (job_id, data_type, doc_id) record. This
document will not be retried.
paramjob_idstrJob ID. Part of the record key.
paramdata_typestrThe pipeline stage. Part of the record key.
paramdoc_idstrDocument ID. Part of the record key.
paramorigin_typestrWho produced the message that failed.
paramorigin_namestrName of the producer.
paramconsumer_typestrWho failed to consume it.
paramconsumer_namestrName of the consumer.
paramerrorstrError text, stored as the hard failure of the record.
methodcount_completed_docsasync (job_id, final_data_type) -> intCount documents that reached the final stage successfully.
paramjob_idstrparamfinal_data_typestrReturns
intNumber of documents with success=True for final_data_type.
methodcount_hard_failed_docsasync (job_id) -> intCount documents that hard-failed at any stage.
paramjob_idstrReturns
intNumber of distinct doc_id values with a hard_failure record.
methodget_stage_countsasync (job_id) -> list[dict]Get per-stage counts for progress display.
paramjob_idstrReturns
list[dict]List of dicts, each containing: {data_type, total, succeeded, soft_failed, hard_failed}.
methodget_doc_statusasync (job_id, doc_id) -> list[dict]Get all stage records for a specific document.
paramjob_idstrparamdoc_idstrReturns
list[dict]List of status records across all stages.
methodget_failuresasync (job_id, data_type=None) -> list[dict]Get all failure records for a job, optionally filtered by stage.
paramjob_idstrparamdata_typestr | None= NoneIf provided, only return failures for this stage.
Returns
list[dict]List of failure records (success=False).
methodget_unique_errorsasync (job_id, data_type=None) -> list[dict]Group the failed records of a job by their current error.
The current error of a record is its hard failure, or else its last
soft-failure reason. Earlier soft-failure reasons are not counted.
count is the number of records (document and stage) in each
group. first_seen and last_seen are the earliest and latest
update time of those records.
paramjob_idstrparamdata_typestr | None= NoneIf provided, only return errors for this stage.
Returns
list[dict]List of {error, count, data_type, first_seen, last_seen}.