jobs

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 18 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 jobs is bitc's detached-job record (spec 7).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastExit

func LastExit(b []byte) (int, bool)

LastExit returns the code of the last line that starts "__EXIT__ <int>". The log is read as text: a NUL is an ordinary byte, so "__EXIT__" after a NUL is mid-line.

func SupervisorDead

func SupervisorDead(st Status) bool

SupervisorDead reports whether st's supervisor is gone: its pid is dead, reused (another start time) or a zombie (a non-reaping PID 1 keeps it as Z). No pid yet is not dead. wait, cancel and sweep (1.9) share it.

func Tail

func Tail(b []byte, n int) []string

Tail returns the last n lines (without trailing empty line).

func Terminate

func Terminate(log *os.File) func(code int) error

Terminate returns a function that ends the log with "__EXIT__ <code>" on its own line. The last byte is read through the job's own fd (lastByte), so a rerun that replaced the path never confuses it.

func Wait

func Wait(o WaitOptions) (string, int)

Wait polls until the job ends or the timeout passes; it returns stdout and the exit code.

Types

type Record

type Record struct {
	Dir, WT8, Name string
	// contains filtered or unexported fields
}

Record is jobs/<wt8>/<name>/.

func Open

func Open(l state.Layout, wt8, name string) Record

func Resolve

func Resolve(l state.Layout, wt8, job string) (Record, error)

Resolve finds <name> in the cwd's work tree, or <wt8>/<name>; 66 when absent.

func (Record) Bump

func (r Record) Bump() (int, error)

Bump starts a new generation under the record lock, moving the old one to prev-<gen>/.

func (Record) Gen

func (r Record) Gen() int

Gen is the current generation (0 if none).

func (Record) Lock

func (r Record) Lock() (func(), error)

Lock takes the record flock (bounded).

func (Record) LogFor

func (r Record) LogFor(gen int, specLog string) string

LogFor is where generation gen's log is now: a default log (<record>/out.log) moves to prev-<gen>/ when a rerun supersedes the generation, so a reader bound to gen follows it.

func (Record) ReadResult

func (r Record) ReadResult(gen int, v any) error

ReadResult returns result.json of gen; os.ErrNotExist while the job runs.

func (Record) ReadSpec

func (r Record) ReadSpec(gen int) (Spec, error)

func (Record) ReadStatus

func (r Record) ReadStatus(gen int) (Status, error)

func (Record) UpdateStatus

func (r Record) UpdateStatus(gen int, f func(*Status)) error

UpdateStatus applies f to gen's status.json (zero if absent) under the record lock, so detach and the supervisor never drop each other's writes; a superseded gen updates its prev-<gen>/.

func (Record) WriteResult

func (r Record) WriteResult(gen int, v any) error

func (Record) WriteSpec

func (r Record) WriteSpec(s Spec) error

func (Record) WriteStatus

func (r Record) WriteStatus(s Status) error

type Spec

type Spec struct {
	Gen    int          `json:"gen"`
	Name   string       `json:"name"`
	WT8    string       `json:"wt8"`
	Log    string       `json:"log"`
	Args   []string     `json:"args"` // run args without --detach
	Cwd    string       `json:"cwd"`
	Flags  config.Flags `json:"flags"`
	Result string       `json:"result,omitempty"` // --result PATH
}

Spec is spec.json: what the supervisor replays. The caller's env is passed through the supervisor's process environment, never written to disk.

type Status

type Status struct {
	State     string `json:"state"` // queued | running | ended
	Gen       int    `json:"gen"`
	Pid       int    `json:"pid"`
	Start     uint64 `json:"start"`
	Log       string `json:"log"`
	StartedAt string `json:"started_at"`
	EndedAt   string `json:"ended_at,omitempty"`
	// CancelRequested is a cancel that arrived while the job was queued ("TERM" or "KILL"): the
	// supervisor reads it when it flips to running, under the record lock.
	CancelRequested string `json:"cancel_requested,omitempty"`
}

Status is status.json.

type WaitOptions

type WaitOptions struct {
	Record  *Record // nil with LogPath
	LogPath string  // --log PATH: a log with no record (legacy J8/J9)
	Timeout time.Duration
	Poll    time.Duration // 10s, scaled by [test] time_scale
	ExitJob bool          // --exit job
}

WaitOptions configure a bounded wait (spec 3.2).

Jump to

Keyboard shortcuts

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