★ Final Challenge

Dependency-Aware Job Runner

100 pts

Everything 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, Run returns an error before invoking any Fn.
  • Ordering. A job's Fn starts only after every one of its dependencies' Fns has returned nil. Each job runs exactly once.
  • Parallelism. At most parallelism Fns 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 Fn returns an error, no new jobs are started (jobs already running may finish), and Run returns that first error. Jobs depending on a failed job never run.
  • Empty jobs map: return nil.
  • Run must 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.