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 Asks(def *Definition) map[string]*JobSpec
- func CheckExpr(src string, names []string) error
- func CheckKey(key string) error
- func CheckLocation(loc string) error
- func CheckPattern(pattern string) error
- func CheckText(text string, names []string) error
- func CompileShape(shape map[string]any) (*jsonschema.Schema, error)
- func Fits(schema *jsonschema.Schema, v any) error
- func Given(files map[string]string) func(string) ([]byte, error)
- func HasExpr(text string) bool
- func Input(def *Definition, given any) (any, error)
- func IsOneExpr(text string) bool
- func JobName(name string, asked, attempt int) string
- func Lists(def *Definition) bool
- func NotYAML(err error, src []byte) error
- func OneExpr(text string) (string, bool)
- func Owns(def *Definition, name string) bool
- func Receives(def *Definition) bool
- func Register(t Type)
- func Reserved(name string) bool
- func Resolve(prefix, loc string) string
- func SendsToAddresses(def *Definition) bool
- func Types() []string
- func Values(def *Definition) []string
- func Written(src []byte) (map[string]any, error)
- type Address
- type AddressSender
- type AddressSpec
- type Checker
- func (c *Checker) Address(place string, s *AddressSpec, names ...string)
- func (c *Checker) Approves()
- func (c *Checker) Asked(ask *JobSpec, check func())
- func (c *Checker) Cond(place, src string, names ...string)
- func (c *Checker) DecodeBody(def *Definition, into any) bool
- func (c *Checker) Duration(place, text string, names ...string)
- 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
- func Parse(src []byte, load func(path string) ([]byte, error)) (*Draft, error)
- func ParseAt(file string, src []byte, load func(path string) ([]byte, error)) (*Draft, error)
- func ParseIn(file string, src []byte, load func(path string) ([]byte, error)) (*Draft, error)
- func ParseMade(src []byte, load func(path string) ([]byte, error)) (*Draft, error)
- func (d *Draft) Hash() string
- func (d *Draft) Store(ctx context.Context, s store.Store, ctl, instance string) (blob.Ref, error)
- func (d *Draft) Values() []string
- func (d *Draft) Write(ctx context.Context, write func(typ string, contents []byte) (blob.Ref, error)) (blob.Ref, error)
- func (d *Draft) WrittenOut() []byte
- type Duration
- type Ending
- type Error
- type Evaluator
- func (e *Evaluator) Cond(src string, scope Scope, place string) (bool, error)
- func (e *Evaluator) Duration(text string, scope Scope, place string) (Duration, 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) Key(text string, scope Scope, place string) (string, error)
- func (e *Evaluator) Text(text string, scope Scope, place string) (any, error)
- func (e *Evaluator) Title(text string, scope Scope, place string) (string, error)
- type Event
- type Field
- type Fields
- func (f *Fields) Bool(name string) bool
- func (f *Fields) Cond(name string) string
- 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 Found
- type Job
- type JobSpec
- type Keeper
- type Kind
- type Limiter
- type Owner
- type Parser
- func (p *Parser) Address(place string, written any) AddressSpec
- func (p *Parser) Ask(place string, s *JobSpec)
- 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) Limits() *Fields
- func (p *Parser) Machine(place string, written any) (name string)
- func (p *Parser) MachineType(name string) string
- func (p *Parser) Nearer(read func())
- func (p *Parser) Problem(place, format string, args ...any)
- type PlacedJob
- type Problem
- type Problems
- type Read
- type Reader
- type Receiver
- type Request
- type Restart
- type Run
- type Scope
- type Send
- type SendSpec
- type Shape
- type ShortForm
- type Sorts
- type StepIn
- type StepOut
- type TicketNamed
- type TimerAt
- type Type
Constants ¶
const ( LifetimeSingleton = "singleton" LifetimeKeyed = "keyed" LifetimeTransient = "transient" UpdateRestart = "restart" UpdateDrain = "drain" )
How runs start at a location, and what a changed file does to them.
const ( DefaultKeep = Duration(7 * 24 * 3600e9) DefaultDepth = 16 DefaultTimeout = Duration(5 * 60e9) )
The defaults of a definition that says nothing.
const ( RunName = "run" ValuesName = "values" )
RunName is the name every expression of every type reads its run by, and ValuesName the name it reads the values set at the run's location by.
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 ( RestartFailure = "failure" RestartAlways = "always" DefaultDelay = Duration(time.Second) DefaultLongest = Duration(5 * time.Minute) )
What a restart's when: says, and the delay of a policy that gives none.
const ExprLimit = time.Second
ExprLimit is how long one expression may run.
const KeyLimit = 256
KeyLimit is how long a key may be, in characters.
const Parent = "parent"
Parent is where a send to the machine's parent is addressed.
const TitleLimit = 200
TitleLimit is how long a title may be, in characters.
Variables ¶
var AddressShape = &Shape{Name: "address", What: "an address", Fields: []Field{ {Name: "at", Kind: KindWord, Like: "devices/boiler", Does: "the location: read from the tree's prefix, or a full path from /"}, {Name: "key", Kind: KindWord, Like: "${event.data.room}", Does: "the key, at a keyed location: its run, started if none is running"}, {Name: "run", Kind: KindWord, Like: "${event.data.run}", Does: "one run at the location, by its ID"}, }}
AddressShape is the shape of an address: the run a send goes to.
var CallShape = &Shape{Name: "call", What: "a call", Fields: []Field{ {Name: "at", Kind: KindWord, Like: "services/weather", Does: "the location, which is transient: read from the tree's prefix, or a full path from /"}, }}
CallShape is the shape of a call: the location whose run a job starts.
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 InputForm = ShortForm{Blob: map[string]any{"type": "object", "required": []any{"$blob"}}}
InputForm is the short form of a definition's input. A blob there is the blob itself, and the input may give names its shape does not.
var JobShape = &Shape{Name: "job", What: "a job", Fields: []Field{ {Name: "script", Kind: KindWord, Path: true, Like: "./fetch.js", Does: "a script, which a runner executes: a file beside the definition"}, {Name: "files", Kind: KindList, Path: true, Like: "[./lib.js]", Does: "files the script loads with require"}, {Name: "machine", Kind: KindValue, Path: true, Like: "./child.yaml", Does: "a machine, which the controller starts as a child: a definition beside this one, or written in place"}, {Name: "send", Kind: KindFields, Of: SendShape, Like: "{ to: { at: devices/boiler }, event: set }", Does: "an event sent to a run by its address; the job ends done once it is sent"}, {Name: "call", Kind: KindFields, Of: CallShape, Like: "{ at: services/weather }", Does: "a location whose run is started with the input; the job waits, and its output is that run's result"}, {Name: "input", Kind: KindValue, Like: `{ url: "${item}" }`, Does: "what the script, the machine or the called run 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 by default; for a machine, the child's timeout"}, {Name: "restart", Kind: KindFields, Like: "{ when: always, limit: 5 in 1h, delay: 1s to 5m }", Does: "what happens when the job ends", Of: restartShape}, {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.
var SendShape = &Shape{Name: "sent", What: "an event a job sends", Fields: []Field{ {Name: "to", Kind: KindValue, Of: AddressShape, Like: "{ at: devices/boiler }", Does: "the run it goes to: an address, or one expression that gives one, such as ${event.from}"}, {Name: "event", Kind: KindWord, Like: "set", Does: "the event's name"}, {Name: "data", Kind: KindValue, Like: "{ target: 12 }", Does: "what the event carries"}, }}
SendShape is the shape of the event a job sends.
Functions ¶
func Asks ¶ added in v0.12.0
func Asks(def *Definition) map[string]*JobSpec
Asks gives the asks a definition writes, by place.
func CheckKey ¶ added in v0.12.0
CheckKey says what is wrong with a key. A key is any text of at most KeyLimit characters that is not empty, and no name in the store holds it.
func CheckLocation ¶ added in v0.17.0
CheckLocation says what is wrong with a location as an address or a receive: entry writes it: a path under the tree's prefix, or a full path from /.
func CheckPattern ¶ added in v0.17.0
CheckPattern says what is wrong with a pattern of locations, where * is any part of one name and ** any number of names.
func CompileShape ¶ added in v0.8.0
func CompileShape(shape map[string]any) (*jsonschema.Schema, error)
CompileShape reads a shape in full form as JSON Schema. A $ref resolves only within the shape: the check runs on the client and again on the controller, and neither reads a file or connects anywhere for one.
func Fits ¶ added in v0.8.0
func Fits(schema *jsonschema.Schema, v any) error
Fits checks a value against a shape, and says each place in it that does not fit and what is wrong there.
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.
func Input ¶ added in v0.8.0
func Input(def *Definition, given any) (any, error)
Input gives what an instance of a definition is started with: the input it was given, with each default its shape gives filled in, checked against the shape. A definition with no input: takes any input as it is.
func JobName ¶
JobName adds to a job's name what tells it apart from others asked for under the same name: the times that name has asked before, and the attempt.
func Lists ¶ added in v0.12.0
func Lists(def *Definition) bool
Lists says a definition takes shapes from outside as it runs.
func NotYAML ¶ added in v0.17.0
NotYAML gives the problem of a file the YAML reader refused, naming the line it is on.
func Owns ¶ added in v0.17.0
func Owns(def *Definition, name string) bool
Owns says whether a name is one a definition gives its own events.
func Receives ¶ added in v0.17.0
func Receives(def *Definition) bool
Receives says a definition's type takes events sent to its runs.
func Reserved ¶ added in v0.12.0
Reserved says whether a name is one Corbie gives a machine itself, which no client, machine or script can send.
func Resolve ¶ added in v0.17.0
Resolve gives a location from a tree's prefix: one written from / is a full path, and any other is read from the prefix.
func SendsToAddresses ¶ added in v0.17.0
func SendsToAddresses(def *Definition) bool
SendsToAddresses says a definition's type can send an event to a run by its address.
func Values ¶ added in v0.17.0
func Values(def *Definition) []string
Values gives the names of the values the expressions of a definition read, in order. Its child definitions are not read.
Types ¶
type Address ¶ added in v0.17.0
type Address struct {
At string `json:"at,omitzero"`
Key *string `json:"key,omitzero"`
Run string `json:"run,omitzero"`
Client string `json:"client,omitzero"`
}
An Address names a run: the run of a singleton location, the run for a key at a keyed location, or one run by its ID. As the sender of an event it may name a client instead. A key is kept as it was filled in, empty or past KeyLimit included: such a send is undelivered, and fails nothing.
type AddressSender ¶ added in v0.17.0
type AddressSender interface {
SendsToAddresses()
}
An AddressSender is a type whose definitions can send an event to a run by its address.
type AddressSpec ¶ added in v0.17.0
type AddressSpec struct {
At string `json:"at,omitzero"`
Key string `json:"key,omitzero"`
Run string `json:"run,omitzero"`
Expr string `json:"expr,omitzero"`
}
An AddressSpec is an address as a definition writes it: a location with a key or a run, each text or text with expressions, or exactly one expression that gives a whole address.
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) Address ¶ added in v0.17.0
func (c *Checker) Address(place string, s *AddressSpec, names ...string)
Address checks an address, whose expressions may read the names. A location written out is checked here, and one with expressions when it is filled in.
func (*Checker) Approves ¶ added in v0.12.0
func (c *Checker) Approves()
Approves notes that the definition holds something for approval other than a job marked for it, which needs an ask as such a job does.
func (*Checker) Asked ¶ added in v0.12.0
Asked checks jobs that go to an ask of their own when they are held, an ask nearer than the definition's: they need no ask from the definition or above it. With no ask of their own they go to the definition's.
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) Duration ¶ added in v0.7.0
Duration checks a length of time: written out, or with expressions, which may read the names.
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 map[string]any `json:"input,omitzero"` // the shape of its input
Keep Duration `json:"keep,omitzero"` // how long its instances are kept
Timeout string `json:"timeout,omitzero"` // how long an instance may run: a length of time, or an expression
Title string `json:"title,omitzero"` // what a run is called: text, or text with expressions
Depth *int `json:"depth,omitzero"` // how many levels of machines may be below it; sixteen 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"`
// Meta is data Corbie keeps with the definition and never reads: no
// expression in it is filled in.
Meta any `json:"meta,omitzero"`
// Lifetime says how runs start at the file's location, and Update what a
// changed file does to those already running. Runs is how many runs of a
// keyed file may be running at once, with no limit at 0. A machine
// written in place or made while running has none of them.
Lifetime string `json:"lifetime,omitzero"`
Update string `json:"update,omitzero"`
Runs int `json:"runs,omitzero"`
// Receive says who may send to the file's runs or call it, by event
// name, with "" for every event. With none, its own tree and its tree's
// client may.
Receive map[string][]string `json:"receive,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"`
// Lines gives the file and the line each value is written at, by its
// place, such as model.name or allow[1]: base.yaml:3.
Lines map[string]string `json:"lines,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.
func ParseAt ¶ added in v0.17.0
ParseAt is ParseIn for a file at a location in a tree. Whether its approvals have an ask to go to is settled when a run starts there: the file may run only as another machine's child, under that machine's ask.
func ParseIn ¶ added in v0.12.0
ParseIn is Parse for a definition kept in a file of the context, by its path from the context. load gives a file by its path from the context.
func ParseMade ¶
ParseMade is Parse for a definition made while a machine runs. Whether its approvals have an ask to go to is left open: that is settled by what is above it when a job is held.
func (*Draft) Hash ¶ added in v0.17.0
Hash gives what a definition runs, as a hash: its stored form, with each file it names by its contents and each child definition by its own hash. Where each value is written takes no part, so moving a line changes nothing.
func (*Draft) Store ¶
Store writes a draft into an instance's record, and gives the stored definition's reference. What bounds how many requests are open at once is a store from store.Bounded.
func (*Draft) Values ¶ added in v0.17.0
Values gives the names of the values the expressions of a draft and of every child definition in it read, in order.
func (*Draft) Write ¶ added in v0.12.0
func (d *Draft) Write(ctx context.Context, write func(typ string, contents []byte) (blob.Ref, error)) (blob.Ref, error)
Write writes a draft a blob at a time: its files and its child definitions side by side, and then the definition itself, which names them. write stores one blob of a type and gives its reference.
func (*Draft) WrittenOut ¶ added in v0.17.0
WrittenOut gives the definition as it is written out, in the order it is written, each value with the file and the line it comes from. A machine written in place is printed in place, and one kept in its own file as its path.
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) Duration ¶ added in v0.7.0
Duration fills in a length of time from a scope's names. Empty text gives none.
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.
func (*Evaluator) Fill ¶
Fill gives a value with every expression in it filled in. Place says where in the definition the value is, for an error to name.
func (*Evaluator) Key ¶ added in v0.12.0
Key fills in a key: text, or text with expressions in it. A value that is neither text nor a number gives empty text, which is no key.
type Event ¶
type Event struct {
Name string `json:"name"`
From string `json:"from,omitzero"`
Data any `json:"data,omitzero"`
// Sender is the run or the client that sent the event to the run by
// its address. Only the controller sets it.
Sender *Address `json:"sender,omitzero"`
// Answer says the event is the answer to a ticket. Only the controller
// sets it, when it takes an answer.
Answer bool `json:"answer,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:"-"`
// Path says what the field holds is a path, or a list of them, read
// from the file it is written in; a mapping there is a machine.
Path bool `json:"-"`
// Many says a value of the field may be a list of what it holds, each
// read by its shape: a list there is no data.
Many bool `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) Cond ¶ added in v0.2.0
Cond takes a field that is a condition: exactly one expression, written ${…}. It gives the expression's source.
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 Found ¶ added in v0.12.0
type Found struct {
Blob blob.Ref `json:"blob"`
Files map[string]blob.Ref `json:"files,omitzero"`
In string `json:"in"`
}
Found is where a job's script or machine is: the blob, the files the script loads, and the name of the definition that holds the job.
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"`
// Found is where the script or the machine is, worked out when the job
// is asked for: what carries it out reads no definition.
Found *Found `json:"found,omitzero"`
// Send is an event the job sends to a run by its address, and Call a
// location whose run the job starts and waits for.
Send *Send `json:"send,omitzero"`
Call *Address `json:"call,omitzero"`
Input any `json:"input,omitzero"`
Allow []string `json:"allow,omitzero"`
Deny []string `json:"deny,omitzero"`
Timeout Duration `json:"timeout,omitzero"`
Restart *Restart `json:"restart,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"`
// AskAt is where the ask the job goes to when it is held is written,
// where one is nearer than its machine's. Only that comes from a step.
// Ask is what is written there, which the controller reads from the
// definition and fills from the machine's input, once for the held
// jobs of a step that name the same place.
AskAt string `json:"ask_at,omitzero"`
Ask *JobSpec `json:"ask,omitzero"`
// Above says the job is an ask taken from a machine above, whose
// script or machine is in that machine's definition. Only the controller
// sets it.
Above bool `json:"above,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
Send *SendSpec `json:"send,omitzero"` // an event sent to a run by its address
Call *AddressSpec `json:"call,omitzero"` // a location whose run the job starts and waits for
Input any `json:"input,omitzero"`
Allow []string `json:"allow,omitzero"`
Deny []string `json:"deny,omitzero"`
Timeout string `json:"timeout,omitzero"` // a length of time, or an expression that gives one
Restart *Restart `json:"restart,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.
func (*JobSpec) Addressed ¶ added in v0.17.0
Addressed gives what a send or a call job writes beside its input: the address and the event's data, each of which may hold expressions.
type Keeper ¶ added in v0.17.0
A Keeper is a type whose runs keep events sent to them to take later.
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. Where // its reader takes one, a mapping of names, each with such a list, // gives a list for each name. 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 shape: a JSON Schema of an object, or the short form, // 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 Limiter ¶ added in v0.2.0
type Limiter interface {
Limits() []Field
}
A Limiter is a type that adds limits of its own to those every type takes. It reads them with Parser.Limits.
type Owner ¶ added in v0.17.0
type Owner interface {
Owns(def *Definition, name string) bool
}
An Owner is a type that gives events names of its own, such as a timer's or a ticket's, which no sender may take.
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) Address ¶ added in v0.17.0
func (p *Parser) Address(place string, written any) AddressSpec
Address reads an address as it is written: a mapping, or exactly one expression that gives one.
func (*Parser) Ask ¶ added in v0.12.0
Ask notes a job the definition holds as an ask, at its place: a machine run as it takes no ask from above it.
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) Limits ¶ added in v0.2.0
Limits gives the definition's limits, for a type to read those it adds.
func (*Parser) Machine ¶ added in v0.12.0
Machine reads a machine a definition runs, as it is written: the path of a definition, or a definition written in place. It loads it, and gives the name the definition has for it.
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 PlacedJob ¶ added in v0.7.0
A PlacedJob is a job of a definition and its place, such as stages.a.job.
func Jobs ¶ added in v0.7.0
func Jobs(def *Definition) []PlacedJob
Jobs gives every job of a definition with its place, in the order the check visits them.
type Problem ¶
type Problem struct {
File string `json:"file,omitzero"`
Place string `json:"place"`
Text string `json:"text"`
}
A Problem is one thing wrong with a definition: in which file, where, and what. File is the path of the child definition's file, from the directory of the definition, and empty for the definition itself.
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 Reader ¶ added in v0.12.0
type Reader interface {
// Lists says the definition takes shapes from outside as it runs.
Lists(def *Definition) bool
// Asks gives the asks the definition writes, by place. It is never nil.
Asks(def *Definition) map[string]*JobSpec
}
A Reader is a type with a part of its definitions that the controller needs. It reads them as plain JSON, and compiles and evaluates nothing.
type Receiver ¶ added in v0.17.0
type Receiver interface {
Receives()
}
A Receiver is a type whose runs take events sent to them by their address, and so may be keyed.
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
Ticket *TicketNamed `json:"ticket,omitzero"`
Drop string `json:"drop,omitzero"` // the ticket 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 Restart ¶ added in v0.12.0
type Restart struct {
// Always restarts the job after it ends well too, and not only after an
// error or a timeout.
Always bool `json:"always,omitzero"`
// Limit is how many restarts are allowed, in the last Within if it is
// given, and with no Limit there is no end to them.
Limit int `json:"limit,omitzero"`
Within Duration `json:"within,omitzero"`
// Delay is the first wait before a restart, which doubles up to Longest.
Delay Duration `json:"delay"`
Longest Duration `json:"longest"`
}
A Restart says what happens when a job ends. With no policy it runs once.
func (*Restart) Wait ¶ added in v0.12.0
Wait gives how long a restart waits, and how many times the delay has doubled after it, from how many times it had before and how long the attempt that ended stayed up. A delay starts again once an attempt has stayed up for twice its longest wait. A step's process can write any values here, so nothing in them is taken on trust: a wait is always more than nothing, and cannot overflow.
type Run ¶ added in v0.12.0
A Run is what an expression reads of the run it is in: its ID, its location, the context its client submitted from, and the values set at its location or above, by name.
type Send ¶
type Send struct {
To string `json:"to,omitzero"` // "parent", or the name of the job that started the child
At *Address `json:"at,omitzero"` // the run it is sent to, in place of To
Event string `json:"event"`
Data any `json:"data,omitzero"`
}
A Send is a request to send a named event to the parent, to a child, or to a run by its address.
type SendSpec ¶ added in v0.17.0
type SendSpec struct {
To AddressSpec `json:"to"`
Event string `json:"event"`
Data any `json:"data,omitzero"`
}
A SendSpec is an event a job sends, as a definition writes it.
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 ShortForm ¶ added in v0.8.0
A ShortForm is how one place fills out the short form: what a blob is there, and whether a name the shape does not give is refused.
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
Run Run // the run it is
Time time.Time // the time of the step
Seed []byte // the step's own secret, for tickets and random numbers
}
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 TicketNamed ¶ added in v0.2.0
type TicketNamed struct {
ID string `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
}
TicketNamed asks for a ticket to be waited on. ID is the state that issued it; the answer arrives as an event with the ticket's name, from the id.
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.