createExtractionService
@forge/monorepo / backend/src / createExtractionService
Function: createExtractionService()
createExtractionService(
deps):object
Defined in: backend/src/documents/extraction.ts:144
Parameters
deps
Returns
limits
limits:
ExtractionLimits
extract()
extract(
job):Promise<FileExtraction>
Do the extraction. Called by the worker, and directly by a single-process host.
Returns the record it wrote rather than throwing, for every document-shaped problem. The only throw is for a file that is not there, which is a caller error rather than a document one.
Parameters
job
Returns
Promise<FileExtraction>
getExtracted()
getExtracted(
context,id):Promise<{document:ExtractedDocument|null;extraction?:FileExtraction; }>
The extracted document, or null when there is none to read.
Parameters
context
id
Returns
Promise<{ document: ExtractedDocument | null; extraction?: FileExtraction; }>
requestExtraction()
requestExtraction(
context,id,mediaType):Promise<{enqueued:boolean;state:"failed"|"skipped"|"running"|"pending"|"extracted"; }>
Ask for extraction, without waiting for it — AC-2.
Marks the file pending first, then enqueues. That order matters: the reverse would let a worker pick
the job up, extract, and record its outcome before this function overwrote it with pending, losing a
completed extraction to a race that only shows up under load.
Parameters
context
tenantId
id
mediaType
string
Returns
Promise<{ enqueued: boolean; state: "failed" | "skipped" | "running" | "pending" | "extracted"; }>
supportedMediaTypes()
supportedMediaTypes(): readonly
string[]
Types this pipeline can read at all. Exposed so an upload path can decide not to enqueue at all.
Returns
readonly string[]
sweepStuckExtractions()
sweepStuckExtractions(
context,input):Promise<{requeued:number;states:Readonly<Record<string,number>>; }>
Re-enqueue extractions that never finished.
Two shapes, and both are silent without this: a pending file whose enqueue was lost, and a running
file whose worker died. Both are re-requested rather than repaired — the pipeline is idempotent, so
running it again is the repair.
Parameters
context
tenantId
input
limit
number
olderThan
string
Returns
Promise<{ requeued: number; states: Readonly<Record<string, number>>; }>