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

Document Job Status and Recovery After Failures

A caller needs to know whether a submitted file is still waiting, running, finished or lost on the way, and document job status answers that at every poll. DaletParse stores four states in its job index, and the poll route adds a fifth state, stale, for quiet jobs. A watchdog fails any job that stops working, and a boot step fails every job that a restart interrupted midway. As a result, every state, every timer and every restart has a defined outcome, and a careful caller can build recovery around them with no guesswork.

The wider workflow sits in the document intake workflow guide.

Illustration of question and answer cards, clipboard, scale for document job status
Key takeaway

A job is queued, running, completed or failed, and the poll route adds stale for quiet jobs. A watchdog fails a job after 900 seconds without activity. A restart fails every job that was still waiting or running, so a caller must be ready to resubmit.

Which job states a caller can see and what each means

Document job status has four stored states. First, a job is queued when it waits in the line. Next, it is running while the worker holds it.

However, the last two states are final. A job is completed when its result is on disk, and it is failed when the run ended in error. Therefore, a caller can stop polling as soon as it sees either one.

The poll route adds a fifth value. It reports stale when a running job has shown no activity for 300 seconds. In practice, document job status has five values on the wire and four in storage.

Also, a caller never sees another tenant's job. A missing job and a job of another tenant both get the same not found answer. As a result, the poll route cannot be used to guess identifiers.

How the poll answer shows progress for a running job

A poll answer carries a handful of fields. They are the status, the run identifier, the phase number and the phase name. Next come the queue position, the heartbeat age, the estimated seconds left and the page count.

Each field of document job status answers a different question. For example, the queue position says how far back a waiting file sits. Also, the phase name says which stage a running file has reached.

For support, heartbeat age is the most useful part. It counts the seconds since the job last showed activity, rounded to one decimal. Therefore, a growing value means the job may be stuck.

A completed answer returns the result with a 200 reply. If the result file cannot be read, the route returns 502 instead. Meanwhile, the batch queue article explains how the queue position and the estimate are computed.

Why a stale status is a warning and not a failure

A job turns stale after 300 seconds of silence. This stale status is only a label on the poll answer. Instead, the job keeps running, and it may still finish.

Long scans explain many quiet periods. A page batch that waits on a model can show no activity for a while. Therefore, a stale status asks for attention, not for a restart.

Illustration for Document Job Status and Recovery After Failures

What a caller can do when a status turns stale

Never resubmit at once on stale document job status. A second copy of the same file joins the line behind the first, and it doubles the load. Instead, keep polling for a while and note the heartbeat age.

If the job recovers, the stale label disappears and the job continues. Otherwise, the watchdog ends it. Meanwhile, alert a person when a stale status lasts longer than your own limit.

How the watchdog and the timeouts end a stalled job

The watchdog gives document job status a hard limit. A job with no activity for 900 seconds is force-failed, so one stuck file cannot block the line. The watchdog timer is the reason the queue drains.

Also, the worker handles timeouts and crashes. A timeout marks a tenant job failed with a short code, processing_timeout. Any other crash marks it failed with the code processing_failed. For tenant jobs, the public error never carries the raw exception text.

A per-document extraction timeout exists, but it stays off unless an operator sets it. Consequently, the 900-second watchdog is the default backstop.

How a caller can log each failure with a cause

Failed job handling starts on the caller side. Clear failed job handling saves hours of guessing. The service gives no detail on purpose, so failed job handling needs your own context. Keep the source file, the run identifier and the time of each upload.

  • Log the run identifier and the final status of every job.
  • Keep the source file until the result is safely stored.
  • Allow one automatic resubmit, then send the file to a person. This keeps failed job handling predictable.

What happens to waiting jobs when the whole server restarts

A restart ends the worker thread and everything it held. Server restart recovery therefore starts with a boot step. It marks every job that was still queued or running as failed, because those jobs will never finish.

For example, the internal row records the old state, such as server restarted while the job was running. However, a tenant caller sees only the short public error. The boot line in the queue log reports how many leftover jobs were cleaned.

Good server restart recovery needs a clean source file. After a restart, document job status shows failed, so the caller must resubmit the file. The service does not remember the upload for you. Moreover, the expiry rules later remove the failed run folder.

Job status and recovery: Stale status, Watchdog and Happens to waiting

How a graceful shutdown drains the queue before it stops

The graceful shutdown drain starts on a termination signal. The service refuses new jobs with a 503 reply, and it stops taking jobs from the line. The running job then gets a drain timeout, which is 45 seconds by default.

Also, an operator can change that value with the variable DALETPARSE_DRAIN_TIMEOUT. The code advises keeping it below the graceful timeout of the web server. Otherwise, the server stops the process before the drain report is written.

When the wait ends, the graceful shutdown drain writes a drain report. It counts the jobs that finished, the jobs that were interrupted and the jobs that never started. In addition, an interrupted job is marked failed with the code interrupted_by_shutdown.

Waiting jobs follow one of two paths. First, by default, they are marked failed with the code server_shutdown_before_start, and a tenant upload is removed. Second, with replay on, the service saves them in a pending file, then queues them at boot. A saved job whose input file is missing is skipped.

How to write a recovery plan around these job states

A plan maps each document job status to one action. Keep it short enough to follow during an incident, with five rules at most.

  1. Queued or running: keep polling at a steady rate.
  2. Stale: wait, record the heartbeat age, and alert a person after your own limit.
  3. Failed job handling: log the run identifier, then resubmit once from your source file.
  4. Server restart recovery: resubmit every file that had no completed answer.
  5. Completed: fetch the result, store it, and stop polling.

Test the plan for document job status before launch. Server restart recovery needs a real test, and so does the graceful shutdown drain. Send a few files, restart the service on purpose, and check that your caller resubmits what it should. Also, test a shutdown with a waiting job, so that you see the graceful shutdown drain in the log.

Treat every job state as a decision your caller must make

Document job status needs one owner per value. Queued and running mean wait. Stale means a person should look. Failed means resubmit or escalate, and completed means fetch and store.

The service protects document job status with a watchdog, a boot step and a graceful shutdown drain. Your caller must protect the files. Keep the source until the result is stored, and write the recovery plan down. For route and token rules, read the extraction API and command line page.

For background on reply codes such as 502 and 503, see the HTTP semantics standard (opens in new tab). The CISA site (opens in new tab) publishes guidance on incident readiness.

A diagram of 3 connected steps, each with a small drawing: Server restart recovery, Failed job handling.

Questions and answers on this topic from the product team

What states can document job status show?

The job index stores queued, running, completed and failed. The poll route can also report stale after 300 seconds without activity. A stale job is a warning, so it can still finish.

When does the watchdog fail a job?

The watchdog fails a job after 900 seconds without activity. A tenant caller then sees a failed answer with a short public error. The reason stays inside the service, so the caller should log its own context for each upload.

What happens to waiting jobs when the server restarts?

At boot, the service marks every job that was still queued or running as failed. Those jobs will never finish, because the process that held them is gone. The caller must therefore resubmit the file.

How long does a shutdown wait for the running job?

The default drain timeout is 45 seconds, and an operator can change it with an environment variable. After that, the service records what finished, what was interrupted and what never started. Interrupted jobs are marked failed.

Can waiting jobs survive a shutdown?

Yes. With the replay switch on, the service saves waiting jobs to a pending file and queues them again at the next boot, so no work is lost across a restart.

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.