Command Palette

Search for a command to run...

Hectal
Phase 12: Building a Production LLM Service
LLM Engineering · Exercise 3 of 6 PreviousNext
Intermediate

Submit jobs once per idempotency key

Write a class Jobs with submit(key, payload) that returns (job_id, created). The first time a key is seen it creates a job with the id "job-1", "job-2", ... and returns created = True. The same key again returns the same job id and created = False, and creates nothing.

Also add count() that returns how many jobs exist.

What Check tests

  1. New keys create numbered jobs
  2. The same key returns the first job and creates nothing
  3. A repeated key does not use up a job number
  4. count() counts jobs

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.