runnerstate

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package runnerstate holds the local single-runner protocol shared by the runner and its detached starter. Pids alone are never liveness evidence.

Index

Constants

View Source
const (
	RestartDrain = "drain"
	RestartNow   = "now"
)

The restart request modes: RestartDrain has the runner take no new lease and exit once its running jobs finish; RestartNow has it exit at once, cutting them.

Variables

This section is empty.

Functions

func Acquire

func Acquire(dir string) (func(), error)

func AppendAgent

func AppendAgent(dir, line string) error

AppendAgent adds one line to the agents file and keeps every line already in it, comments and lines it does not understand included.

func ClearRestart

func ClearRestart(dir string) error

ClearRestart removes the restart request: the runner that honoured it, and the starter of the next one, leave nothing pending behind.

func ClearStale

func ClearStale(dir string) (pid int, cleared bool, err error)

ClearStale clears a previous runner's pid and metadata only while holding the runner lock. A busy lock returns the live pid and an error wrapping EWOULDBLOCK/EAGAIN: a runner is starting or running, so nothing is cleared. The lock file stays in place; removing it could split starters across two files.

func LoadAgents

func LoadAgents(dir string) ([]string, error)

LoadAgents reads the durable choices, independently of runner liveness. A nil slice means init has not saved choices yet.

func LoadForeman

func LoadForeman(dir string) (string, error)

LoadForeman reads the foreman init saved, as harness/model[@effort]. It is empty when init has not saved one yet.

func LoadParallel

func LoadParallel(dir string) (int, error)

LoadParallel returns the saved init choice, or zero when none was saved.

func MigrateForeman

func MigrateForeman(dir string) error

MigrateForeman moves a foreman choice saved as the file "foreman" to its current name, freeing the path for the foreman's scratch directory. A directory there is the scratch directory and stays; a choice already saved under the current name wins over the old file.

Foreman turns and attaches may migrate at once: a call that loses the race to another finds no old file left and succeeds.

func Publish

func Publish(dir string, agents []api.Agent, specs ...string) error

func PublishParallel

func PublishParallel(dir string, agents []api.Agent, parallel int, specs ...string) error

PublishParallel records the live runner capacity beside its agents.

func RequestRestart

func RequestRestart(dir, mode string) error

RequestRestart leaves a restart request for the runner in dir: a small JSON file it honours between jobs — drain finishes its running jobs first, now stops at once. A runner already draining ignores a second request; the fresh starter clears what it finds.

func RestartRequested

func RestartRequested(dir string) (string, bool)

RestartRequested reads the pending restart request: its mode, and whether one is pending at all. A file that cannot be read or parsed counts as none — the runner never exits on a request it cannot understand.

func SaveAgents

func SaveAgents(dir string, specs []string) error

SaveAgents atomically replaces the private, durable runner choices. The live runner.json record is published separately by the runner itself.

func SaveForeman

func SaveForeman(dir, foreman string) error

SaveForeman atomically replaces the private, durable foreman choice.

func SaveParallel

func SaveParallel(dir string, n int) error

SaveParallel atomically saves init's private, durable concurrency choice.

func StalePIDs

func StalePIDs(dir string) []int

StalePIDs returns the pids a previous owner left in dir: the one in runner.lock and the one in runner.json. They are stale only while no fresh runner has cleared them, so a starter reads them before its own child can.

Types

type Record

type Record struct {
	MaxParallel int         `json:"max_parallel,omitempty"`
	PID         int         `json:"pid"`
	Agents      []api.Agent `json:"agents"`
	Specs       []string    `json:"specs,omitempty"`
}

func Running

func Running(dir string) (Record, bool, error)

Running opens an existing lock only; even a read-only probe creates nothing. A stale pid/record is ignored if the kernel lock is free. Metadata is trusted only when it names the lock holder (older runners may have no metadata).

Jump to

Keyboard shortcuts

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