A Queue of Work Records

A work queue can hold an identifier, input values, and enough context for each task to be handled in arrival order.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace changes over two jobs
  2. Know when to keep history
  3. Separate the payload from the identifier
  4. Define the boundary between waiting and finished

Trace changes over two jobs

If A and then B arrive, removing the first queued job yields A. Replacing each record with a shared mutable template can make both entries show B's values. Use record fields to create a separate entry per job.

Know when to keep history

A queue removal can hand work to a processor while a separate record retains completion history. Ensure the input snapshot stays coherent when the caller later edits its own objects. Input ownership defines what the queue keeps.[1]

Separate the payload from the identifier

A queue can contain jobs (17, parse, 2) and (18, parse, 4), where the third field is the attempt number. If job seventeen must be retried, decide whether the original identity stays with the new attempt. Counting attempts and counting jobs then answer different questions. Include the identifier when recording failures so a caller can follow the entire history. See sequence-backed queues.

Define the boundary between waiting and finished

A worker can dequeue a job and stop before storing completion. A queue that forgets an item at dequeue time may lose that job, while acknowledgement-based systems can deliver it again. The processing contract should say which outcomes imply completion and how duplicate attempts are handled. Test a failure after retrieval and before acknowledgement. See retrying a function safely.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩