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
- Variables
- func Collect(dir string, globs []string) ([]string, error)
- func NoPool(err error) bool
- func Pack(dir string, w io.Writer) (int, error)
- func Unpack(r io.Reader, dir string) error
- type Builder
- type Client
- func (c *Client) Builders(ctx context.Context) ([]Builder, error)
- func (c *Client) Cancel(ctx context.Context, id string) (Job, error)
- func (c *Client) Download(ctx context.Context, id, rel string, dst io.Writer) error
- func (c *Client) Finish(ctx context.Context, id string, exit int, errText, log string) error
- func (c *Client) Get(ctx context.Context, id string) (Job, error)
- func (c *Client) List(ctx context.Context, limit int) ([]Job, error)
- func (c *Client) PutInput(ctx context.Context, id string, r io.Reader) error
- func (c *Client) Run(ctx context.Context, spec Spec) (Result, error)
- func (c *Client) Submit(ctx context.Context, r Request) (Job, error)
- type File
- type Job
- type Need
- type Request
- type Result
- type Spec
- type StatusError
Constants ¶
const MaxUnpacked = 8 << 30
MaxUnpacked bounds what an archive may unpack to.
Variables ¶
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.
var PollEvery = 2 * time.Second
PollEvery is how often Run asks the hub how a job stands.
Functions ¶
func Collect ¶
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 ¶
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.
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.
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.
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.
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 ¶
StatusError is an answer of the agent or the hub that was not 200.
func (*StatusError) Error ¶
func (e *StatusError) Error() string