Skip to main content

Practice ยท 2 of 2

The idempotent at-least-once queue

Implement two pieces: InProcessQueue โ€” an at-least-once queue: - enqueue(job_id, payload); deliver() moves all pending jobs (plus anything previously delivered but not acked โ€” simulate lease expiry by re-delivering inflight jobs on the next deliver) and returns the batch as a list of [job_id, payload, attempts] - ack(job_id, result) records completion; fail(job_id, max_attempts=3) increments the attempt counter and re-queues the job, or moves it to the dead-letter list once attempts >= max_attempts - done (dict of results) and dead (list of [job_id, payload, attempts]) expose state process(queue, jobs, max_attempts=3) โ€” a worker loop: - repeatedly deliver() until the queue stays empty - for each job: skip jobs already in done (idempotency!), process 'poison' payloads by calling queue.fail(...), otherwise record the effect and ack(job_id, 'done:' + job_id) - returns (done_dict, dead_list) The discriminating scenario: a job delivered twice must produce exactly one effect; a poison job must be retried until max_attempts then land in dead.

Difficulty: advanced

Back to lesson: Practice: Retry & Redelivery Drills