builders

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: 20 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 builders is the client of the hub's pool of builder machines (docs/hub/builders.md): it lists the builders, hands the hub a heavy job with the files it needs, follows it, takes the result files back, and when the pool has no online builder runs the job on this machine's own heavy slots with draft limits. It talks to the machine agent on the loopback (the agent's /jobs routes), which signs for the hub.

Index

Constants

View Source
const MaxUnpacked = 8 << 30

MaxUnpacked bounds what an archive may unpack to.

Variables

View Source
var ErrNoAgent = errors.New("this machine is not connected to a hub (no agent.json in the data folder)")

ErrNoAgent: this machine has no agent that dials a hub, so there is no pool to ask.

View Source
var PollEvery = 2 * time.Second

PollEvery is how often Run asks the hub how a job stands.

Functions

func Collect

func Collect(dir string, globs []string) ([]string, error)

Collect lists the files under dir that the globs match (a glob matching a folder takes the files in it), as slash paths relative to dir. A glob that leaves dir matches nothing.

func NoPool

func NoPool(err error) bool

NoPool says err means there is no pool to ask: the agent is in no hub (503), or the hub has no builders (404), or the agent is not there. The job then runs here.

func Pack

func Pack(dir string, w io.Writer) (int, error)

Pack writes dir as a tar.gz of regular files and folders (links are left out). It returns the number of files.

func Unpack

func Unpack(r io.Reader, dir string) error

Unpack reads a tar.gz into dir. Names that leave dir, links and special files are refused.

Types

type Builder

type Builder struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Caps    []string `json:"caps"`
	Slots   int      `json:"slots"`
	Running int      `json:"running"`
	Waiting int      `json:"waiting"`
	Online  bool     `json:"online"`
	Ready   bool     `json:"ready"`
	Note    string   `json:"note"`
}

Builder is one machine of the pool.

type Client

type Client struct {
	Base   string // http://127.0.0.1:<port>
	Token  string
	Header string // the header the agent reads its local token from
	HTTP   *http.Client
}

Client talks to the machine agent's /jobs routes on the loopback, which sign for the hub.

func NewLocal

func NewLocal(dataDir, tokenHeader string) (*Client, error)

NewLocal reads the agent's port and token from agent.json in the data folder.

func (*Client) Builders

func (c *Client) Builders(ctx context.Context) ([]Builder, error)

Builders lists the pool.

func (*Client) Cancel

func (c *Client) Cancel(ctx context.Context, id string) (Job, error)

Cancel ends a job.

func (*Client) Download

func (c *Client) Download(ctx context.Context, id, rel string, dst io.Writer) error

Download copies a result file into dst.

func (*Client) Finish

func (c *Client) Finish(ctx context.Context, id string, exit int, errText, log string) error

Finish tells the hub how a local run ended.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (Job, error)

Get reads a job.

func (*Client) List

func (c *Client) List(ctx context.Context, limit int) ([]Job, error)

List reads the space's latest jobs.

func (*Client) PutInput

func (c *Client) PutInput(ctx context.Context, id string, r io.Reader) error

PutInput sends the input archive.

func (*Client) Run

func (c *Client) Run(ctx context.Context, spec Spec) (Result, error)

Run submits the job, follows it to its end and brings the result files back. With no online builder that fits the hub says so and the command runs here, on the machine's heavy slots, with draft limits. A cancelled ctx cancels the job.

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, r Request) (Job, error)

Submit hands the hub a job.

type File

type File struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

File is a result file.

type Job

type Job struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Status string `json:"status"`
	Need   struct {
		Kind string   `json:"kind"`
		Caps []string `json:"caps"`
	} `json:"need"`
	Choice struct {
		Mode    string `json:"mode"`
		Machine string `json:"machine"`
	} `json:"choice"`
	Builder *struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"builder"`
	Local       bool `json:"local"`
	LocalLimits *struct {
		TimeoutSec int    `json:"timeoutSec"`
		Note       string `json:"note"`
	} `json:"localLimits"`
	Reason      string   `json:"reason"`
	ExitCode    *int     `json:"exitCode"`
	Error       string   `json:"error"`
	Log         string   `json:"log"`
	Outputs     []File   `json:"outputs"`
	Argv        []string `json:"argv"`
	OutputGlobs []string `json:"outputGlobs"`
	TimeoutSec  int      `json:"timeoutSec"`
	CreatedAt   string   `json:"createdAt"`
	StartedAt   *string  `json:"startedAt"`
	FinishedAt  *string  `json:"finishedAt"`
}

Job is a job as the hub reports it.

func (Job) Final

func (j Job) Final() bool

Final says the job is over.

type Need

type Need struct {
	Kind    string   `json:"kind"`
	Caps    []string `json:"caps,omitempty"`
	Machine string   `json:"machine,omitempty"`
}

Need is what the job asks of its place.

type Request

type Request struct {
	Title string            `json:"title,omitempty"`
	Need  Need              `json:"need"`
	Argv  []string          `json:"argv"`
	Env   map[string]string `json:"env,omitempty"`
	// Outputs are globs relative to the job's folder.
	Outputs    []string `json:"outputs,omitempty"`
	TimeoutSec int      `json:"timeoutSec,omitempty"`
	HasInput   bool     `json:"hasInput"`
}

Request is what Submit sends.

type Result

type Result struct {
	Job      Job
	ExitCode int
	// Files are the result files, paths relative to Dest.
	Files []string
}

Result is how a job ended.

func RunStandalone

func RunStandalone(ctx context.Context, spec Spec, why string) (Result, error)

RunStandalone is Run on a machine that is in no hub: there is no pool, so the command runs on this machine's own heavy slots as a draft, and the first line says why.

type Spec

type Spec struct {
	Title string
	// Caps are the labels the builder must carry (blender, gpu, ffmpeg...).
	Caps []string
	// Builder is a builder by name or id; "" or "auto" lets the hub choose.
	Builder string
	// Argv is the command, program first (a bare name: blender, ffmpeg).
	Argv []string
	Env  map[string]string
	// InDir is the folder the command runs in: packed and sent to a builder, used in place by a local run. "" is none.
	InDir string
	// Outputs are globs, relative to InDir, of the files the job hands back.
	Outputs []string
	// Dest is where a builder's result files are written, keeping their paths; "" is InDir.
	Dest string
	// Timeout ends the command; 0 is an hour.
	Timeout time.Duration
	// Log gets progress lines and, for a local run, the command's output.
	Log io.Writer
}

Spec is a heavy job as a caller states it.

type StatusError

type StatusError struct {
	Status int
	Text   string
}

StatusError is an answer of the agent or the hub that was not 200.

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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