@sekhmet/job
Named jobs that run as a dependency graph, in the style of GitHub Actions and other CI runners, built on the language's own promises and AbortSignal. A job pairs a pure plan, its dependency list, with a run, which receives that list with each need resolved. A runIf decides, once the needs settle, whether the run is called. Each job runs once per run, however many jobs need it, and ends with a JobEnd: Succeeded, Failed, Skipped, Blocked or Cancelled.
Install
The package is published on JSR.
sh
deno add jsr:@sekhmet/jobFor Node.js, Bun and other npm-compatible runtimes, install through JSR's npm compatibility layer:
sh
npx jsr add @sekhmet/job # npm
pnpm dlx jsr add @sekhmet/job # pnpm
yarn dlx jsr add @sekhmet/job # yarn
bunx jsr add @sekhmet/job # bunExample
ts
import { always, Blocked, defineJobs, runJobs } from "@sekhmet/job";
import { assertEquals } from "@std/assert";
const { job } = defineJobs((_meta: { readonly log: string[] }) => ({}));
const lint = job({
name: "lint",
run: (): void => {
throw new Error("unused variable");
},
});
const build = job({ name: "build", run: () => "dist" });
const deploy = job({
name: "deploy",
plan: (p) => ({ linted: p.needs(lint), site: p.needs(build) }),
run: (r, { site }) => r.meta.log.push(`deployed ${site}`),
});
const cleanup = job({
name: "cleanup",
plan: (p) => ({ deploy: p.needs(deploy) }),
runIf: always(),
run: (r, { deploy }) => {
r.meta.log.push(
`cleaned up after ${deploy.isBlocked() ? "a block" : "a deploy"}`,
);
},
});
const log: string[] = [];
const report = (
await runJobs({ jobs: { deploy, cleanup }, meta: { log } })
).unwrap();
assertEquals(
report.outcomes.deploy,
Blocked(["lint"]),
"deploy should be blocked by the failed lint",
);
assertEquals(
log,
["cleaned up after a block"],
"the always() cleanup should still run, seeing the block",
);
assertEquals(report.passed, false, "a failed lint should fail the run");Learn more
- Tutorial: Getting started builds a deploy pipeline step by step: jobs that need each other, a failure, a cleanup, and the typed report.
- How-to guides: Recipes for needing a job only when another succeeded, cleaning up or notifying after a failure, cleaning up resources, writing your own
runIf, generating jobs from data withfamily, previewing a run, cancelling a run, handing an outcome toResultcode, reporting progress withr.step, and matching on an outcome. - Explanation: Concepts covers plan and run, the three lifetimes (
meta, a job's context and cleanup, steps), conditions as data and the GitHub Actions mapping, once per run, the outcome algebra, planning before running, cancellation, and how job differs from@sekhmet/effect. - Reference: the API reference on JSR documents every export.
The guides are also on the docs site.
Design record
The decision record keeps the history of the package's design decisions and the alternatives they replaced.
License
MIT. See LICENSE.md.