Reliable and fair dispatch queues · Original fictional data · Free files and full answers
Age queue priority using elapsed waiting time
At minute20 effective_score=priority+floor((20-created)/5). Rank queued jobs by score descending, created ascending,id. Return job_id,effective_score,dispatch_position sorted position.
Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.
Your output contract
- At minute20 effective_score=priority+floor((20-created)/5). Rank queued jobs by score descending, created ascending,id. Return job_id,effective_score,dispatch_position sorted position.
- Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.
Return columns exactly as job_id, effective_score, dispatch_position. Sort order follows the task. Output has 6 rows; an empty CSV field means NULL.
Source data
jobs
9 source rows · Download jobs CSV
| id INTEGER | tenant TEXT | priority INTEGER | created INTEGER | status TEXT | lease_until INTEGER | attempts INTEGER | last_attempt INTEGER | skill TEXT |
|---|---|---|---|---|---|---|---|---|
| 1 | A | 3 | 0 | queued | NULL | 0 | NULL | cpu |
| 2 | A | 2 | 2 | running | 25 | 1 | 5 | gpu |
| 3 | A | 1 | 5 | queued | NULL | 2 | 10 | cpu |
| 4 | B | 3 | 1 | queued | NULL | 0 | NULL | gpu |
| 5 | B | 1 | 3 | running | 15 | 3 | 10 | cpu |
| 6 | B | 2 | 4 | queued | NULL | 3 | 12 | cpu |
| 7 | C | 2 | 0 | queued | NULL | 1 | 18 | cpu |
| 8 | C | 3 | 8 | done | NULL | 1 | 12 | gpu |
| 9 | C | 1 | 9 | queued | NULL | 0 | NULL | gpu |
dependencies
4 source rows · Download dependencies CSV
| job_id INTEGER | needs_id INTEGER |
|---|---|
| 3 | 2 |
| 4 | 8 |
| 6 | 5 |
| 9 | 4 |
workers
2 source rows · Download workers CSV
| id TEXT | skill TEXT |
|---|---|
| W1 | cpu |
| W2 | gpu |
Field dictionary and schema
jobs: id INTEGER — Stable source record identifier; not a row position. tenant TEXT — Literal business key or category label. Match exactly and retain NULL where present. priority INTEGER — Higher integer means higher priority in this case. created INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task. status TEXT — Literal lifecycle label; use only statuses eligible in the task. lease_until INTEGER — Exclusive UTC minute until which running ownership remains valid. attempts INTEGER — Number of attempts already made. last_attempt INTEGER — UTC minute of most recent attempt, NULL if never attempted. skill TEXT — Literal business key or category label. Match exactly and retain NULL where present. dependencies: job_id INTEGER — Foreign business-record identifier; match to the named source key. needs_id INTEGER — Foreign business-record identifier; match to the named source key. workers: id TEXT — Stable source record identifier; not a row position. skill TEXT — Literal business key or category label. Match exactly and retain NULL where present.
A method you can reuse
- At minute20 effective_score=priority+floor((20-created)/5). Rank queued jobs by score descending, created ascending,id. Return job_id,effective_score,dispatch_position sorted position.
- For the first output record, job_id = 1; effective_score = 7; dispatch_position = 1.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
Static priority lets old low-priority work starve indefinitely.
Run and check in SQLite
Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.
Complete worked SQL and expected output
WITH x AS (SELECT *,priority+(20-created)/5 score FROM jobs WHERE status='queued') SELECT id job_id,score effective_score,ROW_NUMBER() OVER(ORDER BY score DESC,created,id) dispatch_position FROM x ORDER BY dispatch_position;
"job_id","effective_score","dispatch_position" "1","7","1" "7","6","2" "4","6","3" "6","5","4" "3","4","5" "9","3","6"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects