Skip to content

Glossary ​

The terms of @sekhmet/job's ubiquitous language, each named the way the code names it. The concepts guide explains how they fit together. Terms Sekhmet's packages share, such as Result, Option, enum and variant, Struct, Panic and main and mini, live in the root glossary and aren't redefined here.

Jobs and the graph ​

  • Job (Job<T, M>): a named unit of work in a job graph, pairing a plan with a run. A job is a value: its identity is its JobId, and its name is for display, unique within a run.
  • Job kit (JobKit): what defineJobs returns, job and family, bound to one metadata type and one context factory.
  • Identity (JobId): a job's family and its key within it. The runner runs each identity once per run, however many plans need it.
  • Family (family({ key, define })): a maker of jobs on the fly that gives the same job for the same key, so a graph generated from data dedupes with no cache. A plain job is a family of one.
  • Name: a job's display name, used in reports, events and Blocked. Two identities sharing a name are a DuplicateName graph error.
  • Roots (Roots): the record of jobs a run or dry run starts from; every job reachable from them runs, and each root's outcome comes back under its key.
  • Once per run: within one run each identity runs once, and every dependent gets the same result; a separate run shares nothing.

Plan and run ​

  • Plan (plan(p)): a job's pure, synchronous dependency list, needs in plain records and arrays at any depth. A job that needs nothing omits it.
  • Planner (Planner, the p a plan receives): makes needs with p.needs and p.needsIf, and reads the run's meta.
  • Plan record (PlanRecord): the plain data a plan returns. Plain values beside needs pass through untouched, a second-class escape hatch.
  • Need (Need): a declared dependency on another job. In run it is resolved in place: to the job's value under success(), or to its JobEnd under any other condition.
  • Conditional need (p.needsIf({ job, when })): a need pulled into the graph only when its guard holds, undefined in run otherwise.
  • Guard (Guard): the condition on a conditional need, as data: a description, the needs it reads, and a test over an EndView. Made with succeeded, failed or succeededWith. A guard may read only its own plan's unconditional needs.
  • Run (run(r, needs)): a job's body, any async function, given its needs resolved. Its throw or rejection becomes Failed, never a rethrow.
  • Job run (JobRun, the r a run receives): the run's meta, the job's ctx and cleanup, its signal, and step.
  • Step (r.step({ name, run })): a reported sub-step of a run, which emits step events; calling it after the body finished panics.

Metadata, context and cleanup ​

  • Metadata (meta): the caller's value for the whole run, read by every plan, runIf, factory and body. The caller owns its resources.
  • Context factory (ContextFactory): the function given to defineJobs that builds each job's ctx from meta just before its run. A job that never starts, and a dry run, never call it.
  • Context (ctx): a job's own value from the context factory, unseen by other jobs.
  • Cleanup (Cleanup): a job's cleanup stack, defer, use and adopt, shared by its factory and run and disposed last in first out once the run settles, before the job's terminal event. A cleanup that throws fails its job, keeping an earlier error as SuppressedError does.

Conditions ​

  • Condition (Condition, a job's runIf): whether run is called once the needs settle. It also types run: see condition kind.
  • success(): the default condition: every need succeeded and the run isn't cancelled.
  • failure(): some need is unhealthy.
  • cancelled(): the run was cancelled.
  • always(): whatever happened.
  • Hand-written runIf: a predicate over { meta, cancelled, needs }.
  • Condition kind (ConditionKind): "success", where run gets the needs' values, or "any", where it gets their JobEnds.

Outcomes ​

  • Job end (JobEnd<T>): how a job ended, exactly one of five variants:
    • Succeeded: with what run returned;
    • Failed: with what run threw, or what its factory or cleanup threw;
    • Skipped: its runIf was false, or under the default a need was skipped;
    • Blocked: a need failed or was blocked, so the body never started; it names those needs;
    • Cancelled: the run was cancelled before or while the job ran.
  • Passing / failing (isPassing, isFailing): whether the job did what the run needed. Succeeded and Skipped pass; the rest fail.
  • Healthy / unhealthy (isHealthy, isUnhealthy): whether something broke. Failed and Blocked are unhealthy. Cancelled is the one variant that is healthy yet failing.
  • all: folds a record of outcomes into one, as Promise.all folds promises: Succeeded with every value, or else the worst: Blocked, then Cancelled, then Skipped. It is the default rule under success().
  • continueOnError: lets a job's failure keep the run passing and out of failFast; a job blocked by it still fails the run.
  • Run report (RunReport): what a run that formed a valid graph returns: outcomes, each root's JobEnd under its key, typed; all, every job reached by name; and passed.
  • Verdict (passed): every job reached is passing, or Failed with continueOnError.

Running and planning ​

  • runJobs: runs every job reachable from the roots once, returning a Result of a run report or a graph error.
  • Dry run (planJobs): calls every plan, and no factory or body, and returns the whole JobGraph, guards and conditions included.
  • Job graph (JobGraph, PlannedJob): what a dry run finds: each job's needs with their guards' descriptions, its runIf, its continueOnError and its plan's data.
  • Graph error (GraphError): a graph that can't run, returned as Err before any job starts:
    • DuplicateName: two identities share a name;
    • DuplicateKey: a family built two differently named jobs for one key;
    • UndeclaredGuardRead: a guard reads something other than an unconditional need of its own plan;
    • Cycle: jobs need each other, through needs or conditional needs.
  • Cancellation: a run's signal aborting, or failFast; every body's r.signal aborts, and a job that hasn't started runs only if its runIf holds for a cancelled run.
  • failFast: cancels the run when a job fails without continueOnError.
  • Job event (JobEvent, given to onEvent): Started, StepStarted, StepSucceeded, StepFailed, Finished, Skipped, Blocked and Cancelled, each naming its job, for a front end to watch a run.
  • Misuse panic: a bug in calling code, which panics rather than returning an error: a plan that isn't plain data (NonPlainPlan), a guard reading outside its reads (UndeclaredGuardRead), r.step after the body finished (StepAfterFinish), and a cleanup registered after disposal (CleanupAfterDispose) or given a value it can't dispose (NotDisposable).