GitHub
Skip to content

Library API

The functions and types fleetjobs exports for queueing jobs from a program, scheduling them, replaying logs and reading the job record.

Three entries: fleetjobs queues and follows jobs, fleetjobs/schedule holds the scheduler and the replay, and fleetjobs/schema holds the types. All are ES modules for Node 22.20 or later.

import { cancel, status, submit, wait } from "fleetjobs";

const id = await submit(["pnpm", "test"], { lane: "heavy" });
const exit = await wait(id, { output: { stdout: write, stderr: write } });
ts

Queues a command and returns the job id as a string. While a job with the same working directory and argv is queued or running, it returns that job's id and starts nothing.

OptionDefaultMeaning
cwdprocess.cwd()The working directory
lane"heavy""heavy" or "light"
remotefrom HEAVY_LOCAL and HEAVY_REMOTE, else "auto""auto", "any" or "never"
blockingfalseThe caller waits for the job, so it leaves the queue after 10 minutes without a waiter, not 60

Resolves with the job's exit code once it is done. options.output is { stdout, stderr }, two functions that receive each chunk of the job's output as a Uint8Array, from the start of the job. It rejects when the id names no job, and when the job's supervisor died before the job ended.

Resolves with a Job[]: the jobs that are queued or running, and the ones that ended in the last 10 minutes, oldest first.

Stops the job and resolves once its record is done. It does nothing for a job that already ended, and rejects for an unknown id.

import { schedule } from "fleetjobs/schedule";

const decisions = schedule(state, "default");
ts
ExportWhat it is
schedule(state, policy)Pure. Takes a QueueState and "bash" or "default" and returns one Decision for each queued job
SLOTS, HALF_LIFEThe local slot names, and the half-life of the usage count in seconds
replay(logs, options)Runs the scheduler over Logs and returns a ReplayReport, schema fleetjobs/replay@1
REPLAY_SCHEMA"fleetjobs/replay@1"
readLogs(files), defaultLogFiles()Read log files, and list the ones heavy replay reads by default
parseText(text, file), parseJobs(text, file)Parse the bash heavy's text log, and log/jobs.jsonl
emptyLogs()An empty Logs to parse into

ReplayOptions is { policy, from?, to?, hosts? }, where from and to are YYYY-MM-DD and hosts is a list of { name, slots }. The report holds parsed, assumptions, lanes and days; run heavy replay --json to see one.

schedule reads no clock, disk or network: it uses state.now. A Decision is { id, start, slot?, finishAt? } to start a job in start, which is "local" or a host name, or { id, wait }, where wait says why the job waits.

Types and one constant: JOB_SCHEMA, the string "fleetjobs/job@1". The types are Job, QueueState, Decision, Policy, Host, Mirror, Sinks, Transport and TrustEntry. The Job fields are in the job record.