GitHub
Skip to content

How jobs are placed

How fleetjobs decides where a queued job runs, which jobs may leave this machine, and what the local machine's rules allow.

Every job starts as a record in the store and a supervisor process of its own. The supervisor asks the scheduler where the job should run, waits for that place to have room, then runs the job there. The scheduler is a pure function, schedule(state, policy), in the fleetjobs/schedule entry. It reads the queue, this machine's state and each host's state, and returns one decision for each queued job: start in a place, or wait.

A job waits in one of two lanes. The heavy lane is the default. The light lane, chosen with --light, is for quick commands such as lint or one test file.

LaneSlots on this machineMemory free before a job startsTime limit
heavy2, a third while the machine is idle4 GB1200 s
light1, a second while CPU pressure is low2 GB300 s

The machine counts as idle for the third heavy slot while tasks wait for a CPU under 10% of the time, wait for disk under 25% of the time, and 8 GB are free. The second light slot opens while CPU pressure is under 20% and 4 GB are free. fleetjobs reads pressure stall information from /proc/pressure, because the load average counts processes that wait on disk. Without it, the extra slots stay closed.

The slot counts come from the local block of the config file. A job over its time limit gets TERM, then KILL 30 seconds later. Raise the limit with HEAVY_MAX.

Light jobs are placed before heavy ones. Within a lane the scheduler ranks each job by a score, and the lowest goes first. The score is the checkout's usage, plus the seconds its jobs hold a heavy slot now, minus the seconds this job has waited. A checkout is the nearest folder up that holds .git, and its usage is the slot seconds its heavy jobs used here lately, halved every 30 minutes. So a session that used little goes first, and waiting lowers the score. A short job, whose last runs took 30 seconds or less, starts 10 minutes ahead. A job that goes back to run here after a remote result, class confirm, goes before everything.

A job may run on a host only when all of these hold:

  • It is in the heavy lane.
  • HEAVY_LOCAL is not 1.
  • The config lists at least one host.
  • Its command is a build, test, typecheck or lint, such as pnpm test, vitest, tsc or pnpm build. HEAVY_REMOTE=1 lifts this for any command. A command with a word that installs, deploys, serves or drives a browser, such as install, dev, docker or wrangler, stays here unless HEAVY_REMOTE=1 is set.
  • It runs inside a git checkout whose origin is not matched by a never pattern in the config.
  • No argument names a path outside the checkout or under /tmp.
  • No .env, .env.*, .dev.vars or .pem file is within four levels of the checkout's root, other than .example, .sample and .template files, and .npmrc holds no _auth line.
  • The checkout has a pnpm-lock.yaml or package-lock.json to install from. With HEAVY_REMOTE=1, a checkout with neither is also allowed.

A job that fails any of these runs here, and heavy says why on stderr.

The default policy lets each job, in score order, take the place where it finishes first. For a slot here, that is when the slot frees plus the job's estimate, taken from its last runs. For a slot on a host, it is when the slot frees, plus the time to copy the checkout, plus the estimate divided by the host's speed. When that place is busy, the job waits for it and holds it, so a later job cannot take it first, and a later job may still start at once somewhere else. A host that is down, short of memory or disk, or busy with other work takes no jobs.

Hosts are probed over ssh at most every 15 seconds, and every 2 minutes while one is down. A host that refuses a job rests for a minute, and the job goes back to the queue here.

The bash policy follows the rules the old bash heavy logged, and exists so heavy replay can compare the two. See replay.

A command with dev, serve, preview, start or watch in it holds memory, not CPU, and would keep a slot for its whole life. It runs at once, outside the queue, under the same time limit.

Each job runs in its own systemd scope under the slice HEAVY_SLICE, so the kernel's out-of-memory killer picks the job and not your session. A job that the kernel kills exits with 137. fleetjobs waits up to HEAVY_OOM_WAIT seconds for the job's peak memory plus 2 GB to be free, then retries it once. A second kill queues the job for the night queue.