Documentation
¶
Overview ¶
Package machine is what every machine type shares: the definition, values filled in from input, the events a machine receives, the requests it makes, and the contract a type keeps with the controller.
Index ¶
- Constants
- Variables
- func CheckExpr(src string, names []string) error
- func CheckText(text string, names []string) error
- func Given(files map[string]string) func(string) ([]byte, error)
- func HasExpr(text string) bool
- func IsOneExpr(text string) bool
- func JobName(name string, asked, attempt int) string
- func Register(t Type)
- func Types() []string
- func Written(src []byte) (map[string]any, error)
- type Checker
- func (c *Checker) Cond(place, src string, names ...string)
- func (c *Checker) DecodeBody(def *Definition, into any) bool
- func (c *Checker) Job(place string, s *JobSpec, names ...string)
- func (c *Checker) Name(place, name string)
- func (c *Checker) Problem(place, format string, args ...any)
- func (c *Checker) Value(place string, value any, names ...string)
- type Definition
- type Description
- type Draft
- type Duration
- type Ending
- type Error
- type Evaluator
- func (e *Evaluator) Cond(src string, scope Scope, place string) (bool, error)
- func (e *Evaluator) Entry(entry string, scope Scope, place string) (string, error)
- func (e *Evaluator) Eval(src string, scope Scope) (any, error)
- func (e *Evaluator) Fill(value any, scope Scope, place string) (any, error)
- func (e *Evaluator) Text(text string, scope Scope, place string) (any, error)
- type Event
- type Field
- type Fields
- func (f *Fields) Bool(name string) bool
- func (f *Fields) Done()
- func (f *Fields) Duration(name string) Duration
- func (f *Fields) Fields(name string) *Fields
- func (f *Fields) Has(name string) bool
- func (f *Fields) Int(name string) int
- func (f *Fields) Map(name string) (map[string]any, []string)
- func (f *Fields) Of(name string) *Shape
- func (f *Fields) Place() string
- func (f *Fields) Rest() map[string]any
- func (f *Fields) Size(name string) int64
- func (f *Fields) Strings(name string) []string
- func (f *Fields) Text(name string) string
- func (f *Fields) Value(name string) (any, bool)
- type Job
- type JobSpec
- type KeyNamed
- type Kind
- type Parser
- func (p *Parser) Builtin(name, source string)
- func (p *Parser) Fields(place string, v any, shape *Shape) *Fields
- func (p *Parser) Job(place string, written any) *JobSpec
- func (p *Parser) Load(name string) ([]byte, error)
- func (p *Parser) MachineType(name string) string
- func (p *Parser) Problem(place, format string, args ...any)
- type Problem
- type Problems
- type Read
- type Request
- type Scope
- type Send
- type Shape
- type Sorts
- type StepIn
- type StepOut
- type TimerAt
- type Type
Constants ¶
const ( DefaultKeep = Duration(7 * 24 * 3600e9) DefaultDepth = 8 DefaultTimeout = Duration(5 * 60e9) )
The defaults of a definition that says nothing.
const ( Start = "start" Done = "done" Failed = "failed" Timer = "timer" )
The names of the events Corbie itself sends a machine.
const ( StatusError = "error" StatusTimeout = "timeout" StatusDenied = "denied" StatusCancelled = "cancelled" )
The ways a job fails.
const ExprLimit = time.Second
ExprLimit is how long one expression may run.
const Parent = "parent"
Parent is where a send to the machine's parent is addressed.
Variables ¶
var ErrDefinition = errors.New("the stored definition cannot be used")
ErrDefinition is a stored definition that cannot be used: it is not there, is not a definition, or cannot be read.
var JobShape = &Shape{Name: "job", What: "a job", Fields: []Field{ {Name: "script", Kind: KindWord, Like: "./fetch.js", Does: "a script, which a runner executes: a file beside the definition"}, {Name: "files", Kind: KindList, Like: "[./lib.js]", Does: "files the script loads with require"}, {Name: "machine", Kind: KindValue, Like: "./child.yaml", Does: "a machine, which the controller starts as a child: a definition beside this one, or written in place"}, {Name: "input", Kind: KindValue, Like: `{ url: "${item}" }`, Does: "what the script or the machine is given"}, {Name: "allow", Kind: KindList, Like: "[net:example.com]", Does: "what the job may do, with the definition's allow; for a machine, it narrows everything the child does"}, {Name: "deny", Kind: KindList, Like: "[exec]", Does: "what the job may not do"}, {Name: "timeout", Kind: KindDuration, Like: "5m", Does: "how long it may take: five minutes unless it says; for a machine, the child's deadline"}, {Name: "attempts", Kind: KindNumber, Like: "3", Does: "how many times it is tried on an error or a timeout"}, {Name: "memory", Kind: KindSize, Like: "256MB", Does: "the most memory the job may use"}, {Name: "tags", Kind: KindList, Like: "[gpu]", Does: "chooses runners: one that has every tag"}, {Name: "approve", Kind: KindFlag, Like: "true", Does: "wait for the definition's ask to approve it"}, }}
JobShape is the shape of a job, wherever one is written.
Functions ¶
func Given ¶
Given gives a loader of the files handed over with a definition as text, each under the path the definition names it by.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
A Checker gathers what is wrong with a definition in full form. The client and the controller check with this same code.
func (*Checker) DecodeBody ¶
func (c *Checker) DecodeBody(def *Definition, into any) bool
DecodeBody reads a definition's body into a type's own form, strictly: a field the type does not know is a problem.
func (*Checker) Name ¶
Name checks a name: of a machine, a stage, a state, a tool, a job. An expression in a name is refused.
type Definition ¶
type Definition struct {
Type string `json:"type"`
Name string `json:"name"`
Input []string `json:"input,omitzero"` // the inputs it needs
Keep Duration `json:"keep,omitzero"` // how long its instances are kept
Deadline Duration `json:"deadline,omitzero"` // how long an instance may run
Depth *int `json:"depth,omitzero"` // how many levels of machines may be below it; eight if not said
Jobs int `json:"jobs,omitzero"` // how many jobs an instance may start
Allow []string `json:"allow,omitzero"`
Deny []string `json:"deny,omitzero"`
// AskAbout lists the permissions that must be asked about.
AskAbout []string `json:"ask_about,omitzero"`
Ask *JobSpec `json:"ask,omitzero"`
// Body is the type's own part.
Body jsontext.Value `json:"body"`
// Scripts and Machines are the files and child definitions the
// definition names, each a blob beside the stored definition.
Scripts map[string]blob.Ref `json:"scripts,omitzero"`
Machines map[string]blob.Ref `json:"machines,omitzero"`
}
A Definition is a machine's definition in its one full form, which is what is stored and run. A written definition is filled out into it.
func Decode ¶
func Decode(contents []byte) (*Definition, error)
Decode reads a stored definition, strictly.
type Description ¶
A Description is everything a definition of one type may hold: each mapping's shape, by its name. The definition itself is two of them together, as it is read: "definition" is its first line and what every type takes, and the shape named as the type is the type's own.
func Describe ¶
func Describe(name string) (*Description, bool)
Describe gives what a definition of a type may hold, as its reader reads it.
type Draft ¶
type Draft struct {
Definition *Definition
Files map[string][]byte
Children map[string]*Draft
// contains filtered or unexported fields
}
A Draft is a definition filled out and checked, with the contents of the files it names and the drafts of its child definitions, ready to be stored.
func Parse ¶
Parse reads a written definition, fills it out, and checks it. load gives the contents of a file the definition names, by its path. A definition that holds a job for approval and has no ask for it to go to is refused.
type Duration ¶
A Duration is a length of time as definitions write it: 90s, 5m, 48h, 7d.
func ParseDuration ¶
ParseDuration reads a length of time.
func (Duration) MarshalText ¶
func (*Duration) UnmarshalText ¶
type Error ¶
type Error struct {
Status string `json:"status"`
Error string `json:"error"`
Output any `json:"output,omitzero"`
// A denial says what was refused, which layer refused it and what
// would fix it, and passes up unchanged.
Refused string `json:"refused,omitzero"`
Layer string `json:"layer,omitzero"`
Fix string `json:"fix,omitzero"`
}
An Error is how a job or a machine failed. It is the data of a failed event, with whatever output the job still gave.
func Unhandled ¶
Unhandled gives the failure of a machine that had no rule for the failure of one of its jobs: its error names the job and then gives the job's own. A denial passes through unchanged, with what was refused, which layer refused it and what would fix it; anything else that failed a job fails its machine with an error.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
An Evaluator fills in the expressions of one step. The time expressions see is the time of the step, and their random numbers follow from the step's seed: taken again, the step sees the same.
func NewEvaluator ¶
NewEvaluator makes the evaluator of a step.
func (*Evaluator) Entry ¶
Entry fills in a permission's scope from a scope's names. What fills it must be there, and be text that is not empty or a number: an empty value would turn ${input.dir}/** into /**, the whole disk, and a value that itself holds ${ would be read a second time.
type Event ¶
type Event struct {
Name string `json:"name"`
From string `json:"from,omitzero"`
Data any `json:"data,omitzero"`
}
An Event is anything that reaches a machine: a name, where it came from, and its data.
type Field ¶
type Field struct {
Name string `json:"name"`
Kind Kind `json:"kind"`
// Does says what the field is for, in a line.
Does string `json:"does"`
// Like is the field as it is written, by example: what stands after
// its name.
Like string `json:"like,omitzero"`
// Of is the shape of the mappings the field holds: of the one mapping
// of a field that is fields, of each named thing of one that is named,
// and, of a value, of a mapping written there where a shorter form
// could be. A job holds the shape of a job, and needs none said.
Of *Shape `json:"-"`
// Values are the values it takes, where they are known. With Open any
// other may be written too: these are then the known ones, and no
// more than that.
Values []string `json:"values,omitzero"`
Open bool `json:"open,omitzero"`
// By names a field beside this one that its values depend on, and
// ValuesBy gives them for each value of that field, with those for
// where that field is not written under "".
By string `json:"by,omitzero"`
ValuesBy map[string][]string `json:"values_by,omitzero"`
}
A Field is one field of a mapping: its name, the kind of value it takes, and what it is for.
func (*Field) Holds ¶
Holds gives the shape of the mappings a field holds: the one it names, and for a job the shape of a job.
func (Field) MarshalJSON ¶
MarshalJSON gives a field as a client is given it, with the shape it holds named and not written out: a shape may hold itself.
type Fields ¶
type Fields struct {
// contains filtered or unexported fields
}
Fields reads the fields of a mapping one at a time, by the mapping's shape: it reads no field the shape does not name, and any field left when it is done is one that does not belong.
func (*Fields) Done ¶
func (f *Fields) Done()
Done reports every field not taken as one that is not known here.
func (*Fields) Fields ¶
Fields starts reading the mapping a field holds, by the shape the field gives it. A field that is not written gives nil.
func (*Fields) Of ¶
Of gives the shape of the mappings a field holds: of each named thing, or of a mapping written where a shorter form could be.
type Job ¶
type Job struct {
// Name says what asked for the job: a stage, a state, a tool, an
// agent's turn, the ask; an item of a list adds its position.
Name string `json:"name"`
Script string `json:"script,omitzero"` // a script of the definition, by its path
Files []string `json:"files,omitzero"` // the files it loads, by their paths
Machine string `json:"machine,omitzero"` // a machine of the definition, by its name
// Stored is a stored definition or script the job's own expression gave.
Stored any `json:"stored,omitzero"`
Input any `json:"input,omitzero"`
Allow []string `json:"allow,omitzero"`
Deny []string `json:"deny,omitzero"`
Timeout Duration `json:"timeout,omitzero"`
Attempts int `json:"attempts,omitzero"`
Memory int64 `json:"memory,omitzero"`
Tags []string `json:"tags,omitzero"`
Approve bool `json:"approve,omitzero"`
// Alone says the job has only its own permissions, and none of the
// lists written for the whole definition.
Alone bool `json:"alone,omitzero"`
// Shown is what the ask is shown about the job, beside its name and
// its input, where the job is held for approval.
Shown any `json:"shown,omitzero"`
// Wants names the emitted values the machine acts on.
Wants []string `json:"wants,omitzero"`
}
A Job is a filled-in request for work: a script, which a runner executes, or a machine, which the controller starts as a child.
type JobSpec ¶
type JobSpec struct {
Script string `json:"script,omitzero"` // a path, or exactly one expression that gives a stored script
Files []string `json:"files,omitzero"` // the files the script loads
Machine string `json:"machine,omitzero"` // a name in Machines, or exactly one expression that gives a stored definition
Input any `json:"input,omitzero"`
Allow []string `json:"allow,omitzero"`
Deny []string `json:"deny,omitzero"`
Timeout Duration `json:"timeout,omitzero"`
Attempts int `json:"attempts,omitzero"`
Memory int64 `json:"memory,omitzero"`
Tags []string `json:"tags,omitzero"`
Approve bool `json:"approve,omitzero"`
// Alone says the job has only its own permissions.
Alone bool `json:"alone,omitzero"`
}
A JobSpec is a job as a definition writes it, its values not yet filled in.
type KeyNamed ¶
type KeyNamed struct {
ID string `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
}
KeyNamed asks for a key to be waited on. ID tells apart keys that wait under one name; the answer arrives as an event with the key's name, from the id.
type Kind ¶
type Kind string
Kind is the kind of value a field takes.
const ( // KindWord is a name or a short value, written out on one line. KindWord Kind = "word" // KindText is text of any length. KindText Kind = "text" // KindNumber is a whole number, and KindFlag true or false. KindNumber Kind = "number" KindFlag Kind = "flag" // KindDuration is a length of time, written like 30s, and KindSize a // size in bytes, written like 256MB. KindDuration Kind = "duration" KindSize Kind = "size" // KindList is a list of texts; one text alone is a list of one. KindList Kind = "list" // KindFields is a mapping with a shape of its own, and KindNamed a // mapping of names, each of which holds a thing of one shape. KindFields Kind = "fields" KindNamed Kind = "named" // KindTypes is a mapping of names, each with the type of its value. KindTypes Kind = "types" // KindJob is a job: the path of a script, or a mapping written as a // job is. KindJob Kind = "job" // KindValue is anything: text, a number, a list, a mapping. Its reader // says what it takes. KindValue Kind = "value" )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
A Parser fills a written definition out into its full form. Everything wrong is gathered and reported together.
func (*Parser) Builtin ¶
Builtin adds a script that comes with Corbie to the definition's files, under a name no path can have.
func (*Parser) Fields ¶
Fields starts reading a mapping of a shape. A value that is not a mapping is a problem, and gives nil.
func (*Parser) Job ¶
Job reads a job as it is written: a mapping, or just the path of a script. It loads the script and its files, or the machine.
func (*Parser) MachineType ¶
MachineType gives the type of a machine the definition names, as a job names it, or nothing for one that is not known until it runs.
type Problems ¶
type Problems []Problem
Problems is everything wrong with a definition, reported together.
func Check ¶
func Check(def *Definition) (Problems, bool)
Check gives everything wrong with a definition in full form. The second result says whether any job in it is held for approval, which needs an ask in the definition or above it.
type Read ¶
A Read is one thing an expression reads of a scope's name that holds named things, as stages holds a flow's stages: the thing's name, and which part of it.
func Reads ¶
Reads lists what the expressions of a text read of one of the scope's names. However a reference is spelt, with a dot or with brackets, it is found. A thing named by a computed value is given the name "*".
type Request ¶
type Request struct {
Job *Job `json:"job,omitzero"`
Cancel string `json:"cancel,omitzero"` // cancel the job of this name
Send *Send `json:"send,omitzero"`
Timer *TimerAt `json:"timer,omitzero"`
Clear string `json:"clear,omitzero"` // cancel the timer of this name
Key *KeyNamed `json:"key,omitzero"`
Drop string `json:"drop,omitzero"` // the key of this id is no longer waited on
End *Ending `json:"end,omitzero"`
Note string `json:"note,omitzero"`
}
A Request is one thing a step asks for. Exactly one field is set.
type Send ¶
type Send struct {
To string `json:"to"` // "parent", or the name of the job that started the child
Event string `json:"event"`
Data any `json:"data,omitzero"`
}
A Send is a request to send a named event to the parent or to a child.
type Shape ¶
type Shape struct {
// Name is what the mapping is called where a field holds one: model,
// tool, job. What is the same as it stands in a sentence: "a model".
Name string `json:"name"`
What string `json:"what"`
Fields []Field `json:"fields"`
// Sorts is there where the mapping is one of several sorts of thing,
// which hold different fields: a model of one service or of another.
Sorts *Sorts `json:"sorts,omitzero"`
}
A Shape is what one mapping of a definition may hold: its fields, in the order a person writes them. It is said once. The reader of definitions reads a mapping by its shape, and can read no field the shape does not name; and a client is given the same shape, to offer the fields to a person. So what is read and what is offered cannot come apart.
type Sorts ¶
type Sorts struct {
// By is the field that says which sort a mapping is, and Fields gives,
// for each value of it, the names of the fields that sort holds.
By string `json:"by"`
Fields map[string][]string `json:"fields"`
// Which says which sort a mapping is where the field that says so is
// not written, from what is: a model's service follows from its name.
Which func(written map[string]any) string `json:"-"`
}
Sorts says a mapping is one of several sorts, told apart by one of its fields, and which of the mapping's fields each sort holds. A field a sort does not hold is one that is not written for it, and is not offered.
type StepIn ¶
type StepIn struct {
Definition *Definition
State jsontext.Value // the state the machine was left in; nil at the start
Events []Event
Input any // what the machine was started with
Time time.Time // the time of the step
Seed []byte // the step's own secret, for keys and random numbers
// HasAsk says an ask applies to the machine: its own, or one above it.
HasAsk bool
}
StepIn is what a step is given. A step's answer depends on nothing else.
type StepOut ¶
type StepOut struct {
State any
Requests []Request
// Ignored lists the events, by their place in StepIn.Events, that the
// machine had no rule for.
Ignored []int
}
StepOut is what a step gives back: the new state and what it asks for.
type Type ¶
type Type interface {
Name() string
// Shape is what a definition of the type may hold of the type's own:
// its fields, and theirs. It is what the type's part is read by.
Shape() *Shape
// Fill reads the type's part of a written definition, by its shape,
// and gives its full form, reporting what is wrong with it to the
// parser.
Fill(p *Parser, f *Fields) any
// Check reports what is wrong with a definition in full form.
Check(c *Checker, def *Definition)
Step(in *StepIn) (*StepOut, error)
// Show gives what a watcher is shown of a state.
Show(def *Definition, state jsontext.Value) any
Manual() string
}
A Type is a kind of machine. It supplies the filling-out of its short forms, the check of its definitions, its step, what a watcher is shown of its state, and its page of the manual.