Build a simple in-memory task queue in Python. Get as far as you can in 20 min.
Implement a class with the following methods:
add_task(task_id, priority, payload)- Adds a task to the queue
- Higher priority numbers = higher priority (e.g., priority 10 runs before priority 1)
payloadcan be any data associated with the task
get_next_task()- Returns the highest priority task and removes it from the queue
- Should return task information (id, priority, payload)
get_status(task_id)- Returns the current status of a task
- Possible statuses:
queued,processing,completed
complete_task(task_id)- Marks a task as completed
queue = TaskQueue()
queue.add_task("task-1", priority=5, payload={"action": "send_email"})
queue.add_task("task-2", priority=10, payload={"action": "process_payment"})
queue.add_task("task-3", priority=1, payload={"action": "log_event"})
print(queue.get_status("task-1")) # "queued"
task = queue.get_next_task() # Returns task-2 (highest priority)
print(queue.get_status("task-2")) # "processing"
queue.complete_task("task-2")
print(queue.get_status("task-2")) # "completed"- Focus on getting a working solution first
- Think aloud as you work — we want to understand your thought process
- Feel free to ask clarifying questions
- You may use AI coding assistants if that's part of your normal workflow