How a batch of files enters the queue with one call
Batch document processing starts with one request. It carries several files, and the multi-file statement route accepts up to twenty files in one call. First, each file is checked on its own, before it joins the queue.
The checks, however, are plain and strict. The extension must be PDF, JPG, JPEG, PNG, TIFF, TIF or WEBP. The file may not be empty or exceed 50 MiB, and the name must stay within 255 bytes after cleanup. Consequently, a file that fails is listed by name in an errors list, and the other files still go in.
Every accepted upload receives its own run identifier, which is a random token. In addition, all files from one call share a single batch identifier. As a result, the answer is a 202 reply. It holds the list of jobs, the list of errors and a count of queued jobs.
- The run identifier names one file and one result.
- The batch identifier names the whole group of files.
- The errors list names each refused file and gives a short reason.
Notably, a 202 reply means accepted, not finished. Therefore, your system should store both identifiers at once, because the files themselves are not returned.
Why a serial queue runs only one job at a time
The web service starts one worker thread. The code sets the maximum number of concurrent jobs to one, so batch document processing is strictly serial. Meanwhile, a second job waits until the first job ends.
This choice shapes all batch document processing in the service, and it is deliberate. Meanwhile, inside one job, the pipeline reads pages in parallel and shares model capacity through its own limits. Therefore, extra queue workers would only fight for the same capacity.
For a team, the consequence is simple. A batch of twenty files is not twenty parallel jobs. Instead, it is twenty jobs in a line, so the last file waits for the nineteen ahead of it. Good batch document processing plans for that wait.
How the queue picks which file runs first in line
Indeed, files are served in order of arrival. The code keeps a counter, and a lower number means an earlier upload. In practice, batch document processing runs the first uploaded file first.
The code offers no priority field for tenants. As a result, an urgent file that arrives after a large batch waits behind it. For example, a team can send urgent files in their own request first.
What the queue position tells a caller who is still waiting
A waiting job reports its queue position. Specifically, position zero means the job is the running job, so no queue position can be lower. Next, a higher number counts the jobs ahead of you, including the one that runs now.
A status poll on a run identifier returns the phase number and name. In addition, it returns the page count and the heartbeat age. In addition, it returns the estimated wait in seconds when an estimate exists.
The queued status changes to running without any action from the caller. Meanwhile, the queue position falls by one each time a job ends. Therefore, a caller that polls every few seconds therefore sees the number shrink.
A cancelled or failed job leaves the line at once. Consequently, the jobs behind it move up, and their estimated wait shrinks. The job status and recovery article describes what happens when a job stalls.
How the estimated wait is calculated and why to doubt it
The service keeps a speed history of past jobs. Specifically, it stores seconds per page for up to fifty runs, and it saves this history to disk. Then a rolling average of those values drives the estimated wait.
For a running job, the estimate is the page count times the average, minus the time already spent. For a waiting job, in contrast, it adds the time left on the running job. Finally, it adds every job ahead of you, plus your own.
This method sharpens as the speed history grows. A first run has no history, so the answer carries no estimated wait at all. Likewise, a ten-page scan and a ten-page native PDF can take very different times.
Treat the estimated wait as a guide for a screen, not as a deadline for a customer. Instead, time your own packs on your own deployment. Then write the measured range into your intake notes, as the pipeline overview also advises.
How to read the results of a whole batch afterward
Three read routes help a caller. They all need a tenant token, and they only show jobs that belong to that tenant.
- The jobs list route returns jobs newest first. Also, it accepts a status filter and a batch filter, and it returns at most one hundred rows per call.
- The results route takes up to one hundred run identifiers, or one batch identifier, and returns each result.
- The job detail route returns one job, with its result when the job is complete.
Each entry in a results answer for batch document processing carries its own status. Therefore, a batch can be partly complete, with some files done and others still running. A good caller of batch document processing treats every file on its own. Indeed, it never waits for the whole group before it reads the early ones.
The same answer reports counts for completed and pending files. Also, use those counts for a progress line on your own screen. For the route list and token rules, read the extraction API and command line page.
How the multi-file route fits behind your own API gateway
This route sits behind your API gateway, which authenticates every caller. Its path is a near match to the protected statement path, but the rule does not cover it. Batch document processing through this route follows the retention period your administrators set.
Two results follow for this route. First, the caller reads those jobs through the batch status route, which lists them by batch identifier. Second, the input file is not deleted when the job ends, because that cleanup applies to owner-bound jobs only.
Do not work around this quietly. Instead, put a gateway with its own authentication in front of the service. Then confirm the behavior on your own build. The retention settings article explains what an expiry changes.
Four habits that keep each batch of files easy to predict
These habits come from the queue design. Moreover, none of them needs extra software.
- Keep each request well under twenty files when files are long. Otherwise, one slow file hides the rest.
- Store the run identifier and the batch identifier before you do anything else.
- Poll at a steady, modest rate, because each poll is cheap but the answer changes slowly.
- Send urgent files in their own request, and hold routine files until the urgent ones finish.
Overall, these habits make batch document processing predictable for the team and for the customer.