heavy

package
v0.16.521 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package heavy keeps the heavy checks agents run (go build and test, vitest, playwright, tsc, eslint) from taking a shared machine away from the people working on it. harnessly puts a small launcher under each of those names on the agents' PATH; it runs `harnessly heavy <tool> ARGS…`, and this package runs the real tool:

  • a light call (go env, go list, tsc --version) runs at once, as if there were no launcher;
  • a heavy call first takes one of the machine's shared slots (a flock on <dir>/slot<n>, for every user of the machine), waits for one up to a limit, and runs under nice and ionice with fewer threads (GOMAXPROCS, -p);
  • when no slot frees up in time it does not run: it says so in words an agent acts on and exits with 75.

The number of slots follows the cores: 1 up to 4, 2 up to 16, one per 8 above. A call inside a slot already held ($HARNESSLY_HEAVY_SLOT, e.g. go test running go build) runs at once. Every heavy call is one line of <dir>/events, which `harnessly heavy stats` counts.

Index

Constants

View Source
const ExitBusy = 75

ExitBusy is the exit code of a heavy call that found no free slot in time (EX_TEMPFAIL).

View Source
const HelpText = `` /* 2085-byte string literal not displayed */

HelpText is `harnessly heavy --help`.

View Source
const Marker = "harnessly heavy"

Marker is in every launcher harnessly writes; a file carrying it is never taken for the real tool.

Variables

View Source
var ErrBusy = errBusy

ErrBusy is Hold's answer when no slot freed up within the wait.

View Source
var Tools = []string{"go", "vitest", "playwright", "tsc", "eslint", "npx", "npm", "pnpm"}

Tools are the names harnessly puts a launcher under.

Functions

func Dir

func Dir(getenv func(string) string) string

Dir is the folder of the slots: $HARNESSLY_HEAVY_DIR, else /var/lib/harnessly-heavy when the machine has one, else /tmp/harnessly-heavy. It is the same for every user of the machine.

func Gentle

func Gentle(argv []string) []string

Gentle is the argv with nice and ionice put before it when the machine has them.

func Heavy

func Heavy(tool string, args []string) bool

Heavy says whether the call takes a slot.

func Hold

func Hold(tool string, wait time.Duration) (release func(), err error)

Hold takes one of the machine's shared slots for work the caller runs itself (a draft render of a 3D scene), waiting up to wait for one. The returned function frees the slot; call it once the work is over. When the slots cannot be kept at all (a read-only folder) the work is let through unheld, as the launcher does. A slot is one of the same flocks the launchers take, so a draft render waits for builds and tests and they for it.

func Run

func Run(args []string, env Env) int

Run is `harnessly heavy [--skip DIR] TOOL ARGS…` and `harnessly heavy stats`; it returns the exit code.

func Slots

func Slots(cpus int) int

Slots is how many heavy checks a machine with this many cores runs at once.

Types

type Env

type Env struct {
	Getenv  func(string) string
	Environ func() []string
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	// CPUs is the number of cores; 0 is runtime.NumCPU.
	CPUs int
	// Poll is how often a waiting call tries the slots again; 0 is 2 s.
	Poll time.Duration
	// Now is the clock; nil is time.Now.
	Now func() time.Time
	// Exec replaces the process with the tool for a light call; nil is syscall.Exec.
	Exec func(path string, argv, env []string) error
	// Getwd is the folder the call runs in; nil is os.Getwd.
	Getwd func() (string, error)
}

Env is what a run depends on outside its arguments; tests replace the parts.

func OSEnv

func OSEnv() Env

OSEnv is the process's own environment.

type Stats

type Stats struct {
	Dir   string `json:"dir"`
	Slots int    `json:"slots"`
	Since string `json:"since"`
	// Ran took a slot at once; Waited took one after waiting; Refused found none in time and did not run; Remote ran
	// on the machine of HARNESSLY_HEAVY_REMOTE.
	Ran     int `json:"ran"`
	Waited  int `json:"waited"`
	Refused int `json:"refused"`
	Remote  int `json:"remote"`
	// WaitP50Ms and WaitMaxMs are over the calls that waited or were refused.
	WaitP50Ms int64          `json:"wait_p50_ms"`
	WaitMaxMs int64          `json:"wait_max_ms"`
	ByTool    map[string]int `json:"by_tool"`
}

Stats counts the heavy calls of <dir>/events since a moment.

func ReadStats

func ReadStats(dir string, since time.Time) (Stats, error)

ReadStats counts the events at or after since.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL