Your question is Promise Queue Class With Retries. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The Farmer's Dog processes delivery-related jobs concurrently, but each job may fail and need to be retried. Implement a bounded job queue that starts with no active jobs, runs at most capacity attempts at once, records successful completion order, and retries failures up to max_retries times.
Because this is a deterministic coding exercise, each job provides the planned result and duration of every attempt. An attempt is an object with duration, a nonnegative integer, and success, a boolean. Jobs are initially queued in input order. When multiple attempts finish at the same time, process them in the order they were started. A retry is placed at the back of the queue after its failed attempt completes. New work is started only after all attempts finishing at the current time have been processed.
Implement run_job_queue(jobs, capacity, max_retries). Return an object with completed, the IDs of jobs that eventually succeed in completion order, and failed, the IDs of jobs that exhaust their attempts without success. Each job has the form {"id": string, "attempts": [{"duration": int, "success": bool}, ...]}. The first attempt is always available, and each later attempt is used only after the previous attempt fails.
def run_job_queue(jobs, capacity, max_retries):