Documentation
¶
Overview ¶
Package client starts runs and reads what happened to them. The command line, the gateway and an application written in Go all use it, so there is one behaviour and one set of words for all of them.
Index ¶
- Constants
- Variables
- func ReadMachine(dir, rel string) (*machine.Draft, string, error)
- func Script(name string, script []byte, job ScriptJob) (*machine.Draft, error)
- func WithFiles(input any, files map[string]InputFile) (any, error)
- type Client
- func (c *Client) Cancel(ctx context.Context, run string, life time.Duration) (string, error)
- func (c *Client) Definition(ctx context.Context, id string) (*machine.Definition, error)
- func (c *Client) Fetch(ctx context.Context, id, path string) (io.Reader, File, error)
- func (c *Client) Files(ctx context.Context, id string) (map[string]File, error)
- func (c *Client) Follow(ctx context.Context, id string, interval time.Duration, tell func(Entry)) (*Run, error)
- func (c *Client) List(ctx context.Context, filter Filter) ([]*Run, error)
- func (c *Client) NewRun() (string, error)
- func (c *Client) Receipt(ctx context.Context, message string) (*instance.Receipt, error)
- func (c *Client) Record(ctx context.Context, id string, tell func(Entry)) (*Run, error)
- func (c *Client) Reply(ctx context.Context, run, ticket string, value any, life time.Duration) (string, error)
- func (c *Client) Send(ctx context.Context, run, event string, data any, life time.Duration) (string, error)
- func (c *Client) SendToKey(ctx context.Context, key, event string, data any, life time.Duration) (string, error)
- func (c *Client) Show(ctx context.Context, id string) (*Run, error)
- func (c *Client) Start(ctx context.Context, draft *machine.Draft, start Start) (string, error)
- func (c *Client) Step(ctx context.Context, id string, number int) (*Entry, error)
- func (c *Client) Tickets(ctx context.Context, id string) (map[string]string, error)
- func (c *Client) Wait(ctx context.Context, id string, interval time.Duration) (*Run, error)
- func (c *Client) WaitReceipt(ctx context.Context, message string, life, interval time.Duration) (*instance.Receipt, error)
- func (c *Client) Watch(ctx context.Context, filter Filter, interval time.Duration, tell func(Update)) error
- type Entry
- type File
- type Filter
- type InputFile
- type Local
- type Machine
- type Run
- type ScriptJob
- type Start
- type Submit
- type Update
Constants ¶
const ( // KeyFile begins the key of a run of a machine in a directory: the rest // is the machine's file, from the context. KeyFile = "file:" // LabelMachine and LabelHash are the labels of a run of a machine in a // directory: its file, and the hash of every file it was read from. LabelMachine = "machine" LabelHash = "hash" )
const ScriptStage = "script"
ScriptStage is the name of the one stage a script is wrapped in.
Variables ¶
var ErrNeverTaken = fmt.Errorf("%w: its start was never taken up", ErrNoRun)
ErrNeverTaken is a run whose start stopped being good before a controller took it up.
var ErrNoFile = errors.New("the run shows no file at the path")
ErrNoFile is a path that names no blob of the run.
var ErrNoKey = errors.New("no run has the key")
ErrNoKey is a key that names no run of this client's.
var ErrNoRecord = errors.New("the run has no record to read")
ErrNoRecord is a run with nothing in its record to read yet: it is waiting to start, or its start was refused.
var ErrNoRun = errors.New("there is no such run")
ErrNoRun is a run that does not exist: it was never started, or it is past keeping and gone.
var ErrNotTaken = errors.New("the message was not taken up: it is no longer good and no receipt has come (is a controller running?)")
ErrNotTaken is a message that stopped being good before a controller answered it.
var ErrStart = errors.New("the start cannot be sent")
ErrStart is a start that cannot be sent as it was given.
var LocalInterval = time.Second
LocalInterval is how long a role in one process sleeps when nothing is due and nothing wakes it.
var Statuses = []string{instance.Running, instance.Done, instance.Failed, instance.Cancelled}
Statuses are the words a listing can be narrowed to by status: what a run that is listed can be.
Functions ¶
func ReadMachine ¶ added in v0.12.0
ReadMachine reads the machine at rel in the context dir. A path in it may name any file inside dir and none outside. It gives the draft and a hash of every file read.
Types ¶
type Client ¶
type Client struct {
ID *identity.Identity
Controller identity.Card
Store store.Store
// Now is the client's clock.
Now func() time.Time
// contains filtered or unexported fields
}
A Client is one party's way into a controller's store. With no identity it is a viewer: it can list the heads the store lets it read and nothing more.
func (*Client) Cancel ¶
Cancel asks for a run to be cancelled. It gives the name of the message, by which its receipt is found. Like a start, a cancel, an event and an answer are each good for the life given, or for a few minutes if it is zero.
func (*Client) Definition ¶
Definition gives the definition a run was started from, in its full form, as it is shown: each script and each machine it names as a blob's type, its size and the path to ask for it by.
func (*Client) Fetch ¶
Fetch gives the contents of a blob of a run, by the path it was shown with.
A path shown in a run's result says where the blob is in the output: report, pages[2]. A path shown anywhere else begins with the place of what holds the blob (steps/<number> or emits/<job>/<number>, which is an entry of the run's record, input or definition) and after the next slash says where the blob is in that.
func (*Client) Files ¶
Files lists the blobs in a run's result by their paths, each with the name it has in the value that holds it. It lists every blob a path of the result fetches: one written out inside a text is among them.
func (*Client) Follow ¶
func (c *Client) Follow(ctx context.Context, id string, interval time.Duration, tell func(Entry)) (*Run, error)
Follow gives each entry of a run's record as it is written, with those of every instance below it, and ends when the run and everything below it have ended, saying how the run ended. Each entry is read once. A look that cannot reach the store is made again at the next interval. A follow that is cut short gives the run as it stands.
func (*Client) List ¶
List gives the runs this party may read, each as its head gives it: every instance, not only roots. A client sees its own; a viewer with access to heads sees everyone's.
func (*Client) NewRun ¶
NewRun chooses the name of a run before it is started, so that an application can note it before anything is sent.
func (*Client) Receipt ¶
Receipt reads the controller's answer to a message this client sent. It gives nil while there is none.
func (*Client) Record ¶
Record gives each entry of a run's record so far, with those of every instance below it, and then the run as it stands: what a follow gives, without staying.
func (*Client) Reply ¶
func (c *Client) Reply(ctx context.Context, run, ticket string, value any, life time.Duration) (string, error)
Reply answers a ticket of a run. The ticket is the authority: any client that holds it may answer.
func (*Client) Send ¶
func (c *Client) Send(ctx context.Context, run, event string, data any, life time.Duration) (string, error)
Send sends a named event to a run.
func (*Client) SendToKey ¶ added in v0.12.0
func (c *Client) SendToKey(ctx context.Context, key, event string, data any, life time.Duration) (string, error)
SendToKey sends a named event to the run with a key.
func (*Client) Show ¶
Show gives one run: where it stands and, once it has ended, how. It is shown from its record: the head may be a moment behind, or not there yet.
func (*Client) Start ¶
Start starts a run of a definition that has been filled out and checked. The definition and its files are written into the run's record first, and then the start is sent. It gives the run's name.
func (*Client) Tickets ¶ added in v0.2.0
Tickets gives the tickets a run is waiting on, each name with its value. The value is the whole right to answer; it is in the record, which only the client that started the run can read.
func (*Client) Wait ¶
Wait stays until a run has ended and gives it. It looks again when this process writes to the store, and otherwise at the interval; a look that cannot reach the store is made again. A wait that is cut short, by the context's limit or by its caller going away, gives the run as it stands.
func (*Client) WaitReceipt ¶
func (c *Client) WaitReceipt(ctx context.Context, message string, life, interval time.Duration) (*instance.Receipt, error)
WaitReceipt stays until the controller has answered a message this client has just sent, and gives the receipt. life is the life the message was sent with. Once the message is no longer good and no receipt has come, the wait ends, saying the message was not taken up. It looks again when this process writes to the store, and otherwise at the interval.
func (*Client) Watch ¶
func (c *Client) Watch(ctx context.Context, filter Filter, interval time.Duration, tell func(Update)) error
Watch follows a listing as it changes: the runs that already exist, then the mark, then each run that appears or changes, until the context ends. A run is given once more when it ends, saying how, also when the listing does not take in the finished. A run that the listing keeps, and that started and ended between two looks, is given once, as new and ended. It writes nothing and asks nothing of the controller. A look that cannot reach the store is made again at the next interval, and nothing is given on its account.
type Entry ¶
type Entry struct {
ID string `json:"id"` // the instance whose record it is in
Time time.Time `json:"time"`
// For a step.
Step int `json:"step,omitzero"`
Events []instance.Arrived `json:"events,omitzero"`
Asks []instance.Ask `json:"asks,omitzero"`
Status string `json:"status,omitzero"`
Shown any `json:"state,omitzero"` // what the machine's type shows of its state
// For an emit.
Job string `json:"job,omitzero"` // the job that emitted
Name string `json:"name,omitzero"`
Data any `json:"data,omitzero"`
}
An Entry is one entry of a run's record as a follower is given it: a step, or a value a job emitted. Values are as they are shown: a blob is its type, its size and the path to ask for it by.
type File ¶
type File struct {
Name string `json:"name,omitzero"`
Type string `json:"type"`
Size int64 `json:"size"`
}
A File is a blob of a run as it is shown: what it is and how large, and no key. Name is what the value that holds it calls it.
type Filter ¶
type Filter struct {
// Labels keeps runs that carry every one of these: a label with a
// value must match it, and one with none need only be there.
Labels map[string]string
// Status keeps runs with this status.
Status string
// Parent keeps the runs this instance started.
Parent string
// Finished takes in the runs that have ended and are still kept.
Finished bool
}
A Filter narrows a listing of runs, or widens it to take in those that have ended.
type InputFile ¶
An InputFile is a file given as input: the name it has as a file, from which the blob's type follows, and its contents.
func (InputFile) MarshalJSON ¶ added in v0.7.0
MarshalJSON refuses a file that Start cannot find in the input: one that is not an InputFile in a map[string]any or a []any.
type Local ¶
type Local struct {
*Client
Memory *store.Memory
Controller *controller.Controller
Runner *runner.Runner
// contains filtered or unexported fields
}
Local is every role in one process with the store in memory: a controller, a runner and a client that trust each other. It is the same loop as on a computer, and each role works under its own row of the table of who may touch what. Nothing is set up beforehand and nothing is left behind.
type Machine ¶ added in v0.12.0
type Machine struct {
Path string // from the directory, such as bridges/listen.yaml
Draft *machine.Draft
Hash string // of every file the draft read
Problem error // what stopped the file being read; the rest is empty
}
A Machine is one machine file of a directory.
func ReadMachines ¶ added in v0.12.0
ReadMachines reads every machine file in dir, and those below it, or in the directories of dir it is given: each *.yaml whose first key gives a type of machine. Any other holds data, or fields to include. A file that cannot be read is given with its Problem.
type Run ¶
type Run struct {
ID string `json:"id"`
Machine string `json:"machine,omitzero"`
Type string `json:"type,omitzero"`
// Status is waiting (to start), running, done, failed or cancelled.
Status string `json:"status"`
// Failure says why a failed run failed: error, timeout or denied.
Failure string `json:"failure,omitzero"`
Error string `json:"error,omitzero"`
// A denial says what was refused, which layer refused it and what
// would fix it.
Refused string `json:"refused,omitzero"`
Layer string `json:"layer,omitzero"`
Fix string `json:"fix,omitzero"`
// Input and Output are shown only to the client that started the
// run.
Input any `json:"input,omitzero"`
Output any `json:"output,omitzero"`
// Used lists the permissions the run used: those of every job in it
// and below it.
Used []string `json:"used,omitzero"`
Step int `json:"step,omitzero"`
Started time.Time `json:"started,omitzero"`
Ended time.Time `json:"ended,omitzero"`
Parent string `json:"parent,omitzero"`
// Key is the run's key, and StartedBy the run whose send started it.
Key string `json:"key,omitzero"`
StartedBy string `json:"started_by,omitzero"`
Jobs int `json:"jobs,omitzero"`
Timers int `json:"timers,omitzero"`
Tickets []string `json:"tickets,omitzero"`
Labels map[string]string `json:"labels,omitzero"`
}
A Run is a run as it is shown, wherever it is shown: the same shape and the same words at the command line, over HTTP and to an application.
type ScriptJob ¶ added in v0.7.0
type ScriptJob struct {
Allow, Deny []string
Timeout string // a length of time, such as 7s
Memory string // a size, such as 64MB
Tags []string
}
ScriptJob is what a script wrapped by Script may do, and its limits, as a definition writes them on a job.
type Start ¶
type Start struct {
// Run is the run's name, if it was chosen beforehand with NewRun.
Run string
// Input is the run's input. An InputFile may stand in place of any
// value in a map[string]any or a []any of it: the file is put into the
// run's record, and stands in the input as a blob. A blob of another of
// this client's runs is carried over by writing it as it was shown, with
// the run it was shown for added: { "$blob": <its path>, "run": <that
// run's ID> }, with or without the type and size it was shown with. The
// blob is copied into the new run's record, and the copy stands in the
// input.
Input any
Labels map[string]string
// Key names the run among this client's running runs.
Key string
// Context is the directory the run was submitted from, which its machines
// read as run.context.
Context string
// Allow narrows what the run, and everything below it, may do.
Allow *permission.Layer
// Timeout is how long the run may take.
Timeout time.Duration
// Secrets are the run's own secrets.
Secrets map[string]string
// Life is how long the start is good for; a few minutes if it says
// nothing.
Life time.Duration
}
A Start is what a start may carry besides its definition.
type Submit ¶ added in v0.12.0
type Submit struct {
Client *Client
Context string // absolute: a machine reads it as run.context
Dirs []string // from the context
Again []string // files, from the context, to start though their run has ended
Interval time.Duration
Say func(format string, args ...any)
// contains filtered or unexported fields
}
A Submit brings the runs of directories of a context into line with their files. It keeps nothing of its own: a run is found by its key, so a Submit made again starts nothing new.
type Update ¶
type Update struct {
Run *Run `json:"run,omitzero"`
New bool `json:"new,omitzero"`
// Listed marks the end of the first listing: everything that already
// existed has been given.
Listed bool `json:"listed,omitzero"`
}
An Update is one thing a watcher of a listing is told: a run that is new or has changed, or the mark of the end of the first listing.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cli is Corbie's command line.
|
Package cli is Corbie's command line. |
|
Package gateway is the client package over HTTP: a route for each thing the package sends and each thing it reads, and streams for what can be followed.
|
Package gateway is the client package over HTTP: a route for each thing the package sends and each thing it reads, and streams for what can be followed. |