jonnifyechomq

The Queue · module 01

The lifecycle

A job has a life, and the whole of it is four sorted sets and one row.

A producer enqueues a job; a worker claims it, runs it, and completes it; a failure retries with a delay or dies into a morgue; a crash returns the job to the queue. There is no separate state table, no lock service, no second index — a job moves between four sorted sets (pending, active, schedule, dead) and its own row carries a state field that says where it is. This module reads that machine: the four sets, the claim and its lease, and the token-fenced completion and recovery.

Four sets, one row

Every transition moves a job between two of the four sets and rewrites its row's state. Pick a transition and read which set a job leaves, which it enters, and what the row says afterward. The map below is the real machine: the five transitions of EchoMQ.Jobs over a fixed example job.

The state machine · pick a transition

pending ZSET · score 0 active ZSET · lease done row DEL'd schedule ZSET · run-at dead ZSET · morgue each transition is one atomic Lua script on one slot

The lifecycle is not a status column you update — it is a set a job is a member of. Move the id, and the state has changed.

The dives

Three dives read the machine in depth, each grounded in real echo/apps/echo_mq code: the four sets and why the members are the ids themselves, the claim and its lease-and-token, and the token-fenced completion plus the recovery transitions.

built page ready to read

Pattern & implementation

Where Redis Patterns Applied teaches the reliable queue — a job's state is the collection it lives in, and every move is atomic so a crash loses nothing — this module is where the pattern lands as one shipped state machine.

the pattern (Redis Patterns Applied)

A reliable queue moves a job between named locations atomically and recovers a crashed worker's job from a visibility timeout. States as locations and The reliable queue teach the move.

the implementation (echo_mq)

EchoMQ.Jobs runs @claim / @complete / @retry / @reap — four sorted sets and one row, every transition one atomic script on one slot.

Take the dives in order, or jump to completion-and-recovery if you already know the four sets and the claim. The next module — Jobs, lanes & the consumer — reads the producer, the fair worker, and the loop that owns the rhythm.

References

Sources

Related in this course