Welcome to the team that runs background work. Jobs enter a FIFO ready queue; a registry tracks each job's status and attempt count; a dispatcher hands work out, retries failures, and dead-letters anything that fails too…
Welcome to the team that runs background work. Jobs enter a FIFO ready queue; a registry tracks each job's status and attempt count; a dispatcher hands work out, retries failures, and dead-letters anything that fails too many times.
This repository has three reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
orchestration/
models.py domain types (Job, JobStatus)
errors.py UnknownJob
queue.py the FIFO ready queue (push / pop / peek / remove)
registry.py per-job status and attempt tracking
dispatcher.py dequeue / ack / nack / dead_letters
service.py OrchestrationService: enqueue / dequeue / ack / nack
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
ack completes a job and takes it out of circulation.nack records a failed attempt and re-queues, until the job has been attempted max_retries times, at which point it is dead-lettered rather than re-queued.Workers keep processing the same job. dequeue returns a job but does not remove it from the ready queue or mark it in flight, so several workers pick up the same work at once.
dequeue returns a different job, or None when the queue is empty.dequeue returns None.Do not change the retry or dead-letter logic as part of this ticket.
A completed job can still be dequeued. After ack, a job should be out of circulation; instead it can be redelivered and processed twice.
ack, dequeue never returns that job again.dequeue is None.Do not change the retry or dead-letter logic as part of this ticket.
A failing job retries forever and never reaches the dead-letter list. nack does not advance the attempt count, and the dead-letter threshold is off by one, so the limit is never hit.
nack advances the job's attempt count by one.max_retries=N, the Nth nack moves the job to the dead-letter list instead of re-queueing.max_retries=1 and max_retries=2 asserting the job dead-letters on the Nth nack.Do not change the dequeue path as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.orchestration/ are submitted; the shipped tests in tests/visible run as they are.Adapted from treasure567/bloomberg-practice (round-2/aperture @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
job-queue-redelivery-and-dead-letters
Changes under src/ are evaluated.