role

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 2 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 role is how a controller or a runner goes about its work, wherever it is hosted: in passes.

Index

Constants

View Source
const Arg = "run-one-job"

Arg is the argument that makes the binary run one piece of work, as the process that is started for it.

View Source
const Grace = 2 * time.Second

Grace is how long a process that is told to stop is given before it is killed, and how long its output is read after it has ended.

View Source
const HostMargin = 10 * time.Second

HostMargin is how long before the host's limit a pass stops taking up new work, to finish what it has in hand.

View Source
const MaxPiece = 64 << 20

MaxPiece bounds one piece; a blob's bytes are not counted.

Variables

This section is empty.

Functions

func Answer added in v0.30.0

func Answer(ctx context.Context, report func(error), handler http.Handler) error

Answer answers the host's HTTP requests until the context ends: each call is one request, given to the handler, whose context ends a margin before the host's limit. report is told of a call that could not be answered.

func Gone added in v0.12.0

func Gone(pid int) bool

Gone says whether no process has this number any more.

func LimitMemory added in v0.12.0

func LimitMemory(limit uint64)

LimitMemory has the system refuse this process more memory than a limit past what it has reserved so far, so that a request for more ends it at once and fills nothing. Go reserves about a gigabyte of addresses it never uses, and the system counts addresses.

func Lost added in v0.12.0

func Lost()

Lost ends the process, and everything it started with it: its starter has gone away, and nothing else would stop them.

func Once

func Once(ctx context.Context, until time.Time, margin time.Duration, pass Pass) (time.Time, error)

Once runs one pass for a host that calls for passes itself and kills a copy at a time it gives. The pass is told to stop taking up new work a margin before that time, or halfway to it where less than two margins are left, and nothing of it goes on after it has answered.

func OwnConfig

func OwnConfig(dir string) (string, error)

OwnConfig gives the config directory a role is to use. A serverless host unpacks its package read-only and readable by everyone, and an identity that others can read is not accepted: there the config is copied to a place of the copy's own, made its owner's alone, and that place is given. Anywhere else the config is used where it is.

func Run

func Run(ctx context.Context, now func() time.Time, report func(role string, err error), roles ...Role)

Run runs each role's passes in a loop until the context ends: a pass, then a sleep until the next thing is due or for the role's interval, whichever is sooner. A role is woken at once when its store reports a write to what it reads; that changes when a pass happens and never what a pass does.

report is told of each pass that failed. Such a pass has failed nothing: what was waiting is still waiting for the next one.

func Serve

func Serve(ctx context.Context, report func(role string, err error), roles ...Role) error

Serve answers the host's calls until the context ends: for each call, one pass of each role, and then the answer. Nothing of a pass goes on after it has answered.

func Serverless

func Serverless() bool

Serverless says whether the process is on a host that calls for passes itself.

func StoreFits

func StoreFits(address string) error

StoreFits refuses, on a serverless host, a store that is a directory or memory. Copies on such a host share no disk and no memory, so each would see a store of its own.

func Watch added in v0.12.0

func Watch(pid int, limit int64, done <-chan struct{}, over func())

Watch calls over when the memory a process really holds goes past a limit: what its engine counts is only its own values.

func WatchOwn added in v0.12.0

func WatchOwn(ctx context.Context, limit int64, over func())

WatchOwn calls over once, when what this process holds passes a limit.

Types

type Pass

type Pass func(ctx context.Context) (next time.Time, err error)

A Pass looks at the store, does everything that is owed, and stops. It says when the next thing is due, if it knows of one. Nothing is carried in memory from one pass to the next.

type Process added in v0.12.0

type Process struct {
	Cmd  *exec.Cmd
	Wire *Wire
	// contains filtered or unexported fields
}

A Process is a process started with a channel to it. Nothing but the starter holds its ends of the channel.

func Start added in v0.12.0

func Start(command []string, dir string, out io.Writer) (*Process, error)

Start starts a command in a group of its own, in a directory, with what it prints going to out.

func (*Process) Close added in v0.12.0

func (p *Process) Close()

Close ends the process and closes the starter's ends of the channel.

func (*Process) Ended added in v0.12.0

func (p *Process) Ended()

Ended sees the process and everything it started gone, and what it printed read to its end.

func (*Process) Kill added in v0.12.0

func (p *Process) Kill()

Kill stops the process and everything it started.

type Role

type Role struct {
	Name     string
	Pass     Pass
	Interval time.Duration
	Notice   <-chan struct{}
}

A Role is one role of a process: its pass, how long it sleeps when nothing is due, and the notice its store gives when something it reads is written.

type Wire added in v0.12.0

type Wire struct {
	R io.Reader
	W io.Writer
	// contains filtered or unexported fields
}

A Wire is one end of the channel.

func Open added in v0.12.0

func Open() (*Wire, error)

Open is how a process started by Start begins: it takes its ends of the channel, and makes itself a group where the system needs that. Everything it starts is in that group, and goes when the group is ended.

func (*Wire) Receive added in v0.12.0

func (w *Wire) Receive(piece any) error

Receive reads one piece.

func (*Wire) ReceiveUpTo added in v0.12.0

func (w *Wire) ReceiveUpTo(limit uint32) ([]byte, error)

ReceiveUpTo reads one piece of at most a number of bytes, as it was sent.

func (*Wire) Send added in v0.12.0

func (w *Wire) Send(piece any, size int64, contents io.Reader) error

Send writes one piece, and the size bytes of contents after it.

Jump to

Keyboard shortcuts

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