DaletGuard supports civilians affected by armed conflict through Families Beyond War. All sides, no political affiliation. About our humanitarian work

Batch Document Processing and the Job Queue

Sending many files at once and collecting each result later beats waiting on every file, and that is what batch document processing in DaletParse does. The service groups uploads under one batch identifier and runs the jobs on a worker queue, one after another. Teams that plan around the queue avoid surprise waits, because they can see where each file sits at any moment, from creation of the batch to the last result a caller reads.

The wider workflow sits in the document intake workflow guide.

Illustration of puzzle, signpost, scale for batch document processing
Key takeaway

The service accepts up to twenty files per request and gives every file its own run identifier. All files in one request share a batch identifier, and a single worker runs them one after another. Plan your wait time from your own test runs.

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.

DaletParse Queue: Serial queue screen

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.

Illustration for Batch Document Processing and the Job Queue

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.

  1. 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.
  2. The results route takes up to one hundred run identifiers, or one batch identifier, and returns each result.
  3. 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.

DaletParse Queue: Poll at a steady screen

Plan the line before the first batch of files ever arrives

A serial queue is easy to reason about. One worker runs one job, and files wait in arrival order. Thus, the queue position tells you how far back a file sits. Measure your own seconds per page, and set batch sizes and polling rhythm from those numbers.

For the daily routine around the line, return to the daily intake routine. You can also see how the review workspace shows finished runs. For background on the reply that starts every batch, see the HTTP semantics standard (opens in new tab).

Likewise, the JSON format page (opens in new tab) describes how each result is written. The NIST site (opens in new tab) publishes security guidance for the services around it.

A diagram of 3 connected steps, each with a small drawing: Queue position, Batch identifier, Estimated wait.

Questions and answers on this topic from the product team

How many files can one batch hold?

The multi-file statement route accepts up to twenty files in one request. Each file gets its own run identifier, and all of them share one batch identifier. A file that fails a check is reported by name in an errors list, while the other files still enter the queue.

Does the queue run several jobs at once?

No, because the code sets the maximum number of concurrent jobs to one. A single worker takes jobs in order. Inside one job, the pipeline can read pages in parallel, but the job queue itself stays serial.

What does the queue position tell a caller?

It shows where the job sits right now, and position zero means the job is running. The estimated wait comes from a rolling average of seconds per page, so it sharpens with every run.

How can I fetch the results of a whole batch?

The tenant jobs routes can list jobs filtered by batch identifier. A results route also takes a batch identifier or up to one hundred run identifiers. Each entry reports its own status, so a batch can be partly complete.

Where does a team set priority between urgent and routine files?

In your own caller. The queue serves files in the order they arrive, and the code offers no priority field for tenants. Therefore, send urgent files in a separate request, and hold routine files back until the urgent ones finish.

See how DaletParse fits the providers your team uses today

Book a short meeting for a walkthrough with your own providers in mind, or join an in-person class to learn the method first.