Checkpoint

Checkpoint: Night Shift Ledger

The night-shift clerk has two jobs.

First, pick the right tool for each job in tonight's plan. Each job says how long it spends waiting (wait_ms) and computing (cpu_ms) per item, and how many items there are (count).

Second, record fuel payments in the guild ledger. Many payments arrive at once as async tasks. Each one reads a balance, waits for a slow write, then saves the new balance. You know what that means: a race condition, unless a lock guards it.

Assignment

  1. pick_tool(job) returns:
    • "plain" if count is 1 or less (check this first);
    • "processes" if cpu_ms is greater than wait_ms;
    • "asyncio" otherwise.
  2. Fix record so the whole read, wait, write runs inside async with lock:. Keep the await asyncio.sleep(0).
  3. Leave run_day as it is. With the lock in place, it returns the right totals.