Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSystem Design for Python JuniorsModule 1 · System Design FundamentalsMessage queuespredict9 / 105
+100 XP
Task
📝 **Task:** Predict the 5-line drain order from a FIFO queue with one transient failure that re-enqueues the failed job to the end. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

from collections import deque

class JobQueue:
    def __init__(self):
        self._q = deque()
    def push(self, job):
        self._q.append(job)
    def pop(self):
        return self._q.popleft() if self._q else None

q = JobQueue()
q.push("send_email:1")           # job 1
q.push("send_email:2")           # job 2
print(q.pop())                   # drain 1 → first-in first-out

q.push("send_email:3")           # job 3
q.push("send_email:4")           # job 4
q.push("send_email:5")           # job 5

# Transient failure on the next pop — retry policy puts it BACK
# on the END of the queue (FIFO order must hold).
failed = q.pop()
q.push(failed)                   # re-enqueued to the tail

# Drain everything remaining.
while True:
    j = q.pop()
    if j is None:
        break
    print(j)

# What does this print? Type your prediction.

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…