Dumebi Okolo describes a queue-backed generation endpoint in Rate Limiting and Queuing Long AI Jobs in Next.js with Upstash Redis and QStash. The example stores a job in Postgres before handing its identifier to QStash, so the browser can poll for the result without keeping the original request open. The point worth examining is what happens to the stored job when a delivery times out.
Follow the job after the worker stops
Okolo's example has a worker claim a pending job with a conditional update to processing. A second delivery cannot make the same transition while the first claim holds. If the worker catches a transient error, it sets the job back to pending and returns a failure response, leaving the next delivery able to claim it. For a permanent error, it records that outcome and acknowledges the delivery.
A worker that stops before it can write either outcome leaves a different trace. The job may still be processing when the next delivery arrives. In the example, an invocation that finds no pending row acknowledges the message as skipped. A job stranded in processing can therefore outlive the delivery attempts. The article raises a separate recovery check for jobs that have spent too long in that state. An operational test can stop a worker just after the claim, then observe the row and the next delivery independently.
Choose a unit of work that fits the deadline
Okolo reports that one scheduled endpoint accounted for all the HTTP 504 errors in the observed delivery history. The article recommends dividing work that regularly runs long into stages, so a retry can repeat a bounded stage. For example, a document generation job could persist the list of sections it plans to generate before starting the first section. Each stage could store its output and identify what remains, giving a later invocation a place to resume.
Upstash's retry documentation describes the delivery deadline and retry behavior. A test that reads both the queue outcome and the application's job row can show whether the browser will eventually see a result or a terminal failure.