★ Final Challenge
› Dependency-Aware Job Runner
100 ptsEverything at once: a build-system core. Implement:
type Job struct {
Deps []string // names of jobs that must succeed first
Fn func() error // the work
}
func Run(jobs map[string]Job, parallelism int) error
Required semantics (parallelism is always >= 1 in the tests):
- Validation first. If any job lists a dependency that isn't a key in
jobs, or the dependency graph contains a cycle,Runreturns an error before invoking anyFn. - Ordering. A job's
Fnstarts only after every one of its dependencies'Fns has returnednil. Each job runs exactly once. - Parallelism. At most
parallelismFns execute at any moment — the tests track an atomic high-water mark of in-flight jobs. Independent jobs must actually overlap: a serial runner (high-water mark 1 with cap 3 and ten independent jobs) fails. - Fail fast. When any
Fnreturns an error, no new jobs are started (jobs already running may finish), andRunreturns that first error. Jobs depending on a failed job never run. - Empty
jobsmap: returnnil. Runmust always return — the tests wrap every call in a deadlock guard.
Suggested shape: validate with Kahn's algorithm (indegree counting — it gives you cycle detection and the ready set), then run a single coordinator loop that launches ready jobs while a completion channel feeds back results. No mutex needed if only the coordinator touches the graph state.
Log in to submit a solution and earn points.