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.
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.
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.
- Queued or running: keep polling at a steady rate.
- Stale: wait, record the heartbeat age, and alert a person after your own limit.
- Failed job handling: log the run identifier, then resubmit once from your source file.
- Server restart recovery: resubmit every file that had no completed answer.
- 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.