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 Addressable(at, lifetime string, keyed bool) string
- func At(year int, month time.Month, day, hour, minute, second int, zone *time.Location) time.Time
- func Calls(def *Definition) []string
- 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 HasBefore(hooks map[string]*HookSpec) bool
- 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 OneExpr(text string) (string, bool)
- func Owns(def *Definition, name string) bool
- func Receives(def *Definition) bool
- func ReceivesFrom(def *Definition, tree string, sender *Address, event string) 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 Zone(name string) (*time.Location, 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) 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) SendTo(place string, to *AddressSpec, event string, names ...string)
- func (c *Checker) Value(place string, value any, names ...string)
- type Definition
- 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) Refuse(name, why 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 HookSpec
- 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) 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) MachineAt(place, at string) *Definition
- func (p *Parser) MachineType(name string) string
- func (p *Parser) Problem(place, format string, args ...any)
- type PlacedJob
- type PlacedSend
- type Problem
- type Problems
- type Read
- type Reader
- type Receiver
- type Recorded
- type Request
- type Restart
- type Run
- type Scope
- type Send
- type SendSpec
- type Shape
- type ShortForm
- type Shown
- type Sorts
- type StepIn
- type StepOut
- type TicketNamed
- type TimerAt
- type Type
- type TypeShape
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 after: 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, Description: "the location: read from the tree's prefix, or a full path from /; alone, the run of a singleton, or a new run of a transient location"}, {Name: "key", Kind: KindWord, Description: "the key, at a keyed location: its run, started if none is running"}, {Name: "run", Kind: KindWord, Description: "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, Description: "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, Description: "a script, which a runner executes: a file beside the definition"}, {Name: "files", Kind: KindList, Path: true, Description: "files the script loads with require"}, {Name: "machine", Kind: KindValue, Path: true, Description: "a machine, which the controller starts as a child: a definition beside this one, or written in place"}, {Name: "send", Kind: KindFields, Of: SendShape, Description: "an event sent to a run by its address; the job ends done once it is sent"}, {Name: "call", Kind: KindFields, Of: CallShape, Description: "a location whose run is started with the input; the job waits, and its output is that run's result"}, {Name: "input", Kind: KindValue, Description: "what the script, the machine or the called run is given"}, {Name: "allow", Kind: KindList, Description: "what the job may do, with the definition's allow; for a machine, it narrows everything the child does"}, {Name: "deny", Kind: KindList, Description: "what the job may not do"}, {Name: "timeout", Kind: KindDuration, Description: "how long it may take, five minutes by default; for a machine, the child's timeout"}, {Name: "restart", Kind: KindFields, Description: "what happens when the job ends", Of: restartShape}, {Name: "memory", Kind: KindSize, Description: "the most memory the job may use"}, {Name: "tags", Kind: KindList, Description: "chooses runners: one that has every tag"}, {Name: "approve", Kind: KindFlag, Description: "marks the job for approval: it starts only after a hook before it"}, {Name: "meta", Kind: KindValue, Description: "data of any kind, which hooks read as job.meta and nothing else reads"}, }}
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, Description: "the run it goes to: an address, or one expression that gives one, such as ${event.from}"}, {Name: "event", Kind: KindWord, Description: "the event's name"}, {Name: "data", Kind: KindValue, Description: "what the event carries"}, }}
SendShape is the shape of the event a job sends.
Functions ¶
func Addressable ¶ added in v0.18.0
Addressable says why a send to { at }, or to { at, key } when keyed, goes to no run at a location of a lifetime, or "" where it may: { at } goes to a singleton's run or starts a new run of a transient location, and { at, key } goes to a keyed location's run for the key.
func At ¶ added in v0.22.0
At gives the moment a zone's clock shows a date and a time of day. A time the clock skips that day is the moment the clock jumps past it, and a time it shows twice is the first. The date may run over, as time.Date's does.
func Calls ¶ added in v0.26.0
func Calls(def *Definition) []string
Calls gives the locations whose recorded machines a run of a definition reads at its first step.
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 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 ReceivesFrom ¶ added in v0.18.0
func ReceivesFrom(def *Definition, tree string, sender *Address, event string) bool
ReceivesFrom says whether a definition's receive: lists a sender for an event, its locations read from the prefix of the tree the definition is in. With no receive:, every location of the tree is listed. A call is the event "": a list takes it, and a mapping, which names events, does not. The tree's own client, which is always listed, is the caller's to know.
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 marks something for approval other than a job, which needs a hook before it as a marked job does.
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"`
// Approve lists the permissions that mark a job for approval: a job
// that declares one starts only after a hook before it.
Approve []string `json:"approve,omitzero"`
// Hooks are the jobs that run before or after the jobs of the machine
// and of the machines below it, by name.
Hooks map[string]*HookSpec `json:"hooks,omitzero"`
// Description says what the machine is for: plain text, with nothing
// filled in.
Description string `json:"description,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"`
// Read names the clients, beside its tree's, that read the records of
// the file's runs, each as client:<name>.
Read []string `json:"read,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 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 marks a job for approval and has no hook before a job is refused.
func ParseAt ¶ added in v0.17.0
func ParseAt(file string, src []byte, load func(path string) ([]byte, error), located func(file string) bool) (*Draft, error)
ParseAt is ParseIn for a file at a location in a tree. Whether its marked jobs have a hook before them is settled when a run starts there: the file may run only as another machine's child, under that machine's hooks. located says whether a file of the context, by its path from it, is a machine at a location of the tree; it is nil for a file read alone, as a tree of its own.
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 marked jobs have a hook before them is left open: that is settled by what is above it when a job is asked for.
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"`
// Principal is the principal a client sent the event for, where the client
// named one. Only the controller sets it, from the client's message.
Principal string `json:"principal,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
Kind Kind
// Description says what the field is for, in a line.
Description string
// 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
// 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
// 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
}
A Field is one field of a mapping: its name, the kind of value it takes, and what it is for.
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, with the fields the mapping takes.
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.
func (*Fields) Refuse ¶ added in v0.21.0
Refuse reports a field that does not belong here, where it is written, with why.
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 HookSpec ¶ added in v0.35.0
type HookSpec struct {
Before *JobSpec `json:"before,omitzero"`
After *JobSpec `json:"after,omitzero"`
When string `json:"when,omitzero"`
}
A HookSpec is a hook as a definition writes it: a job that runs before a job starts or after it has ended done, and the condition on the job that says which jobs it runs for.
type Job ¶
type Job struct {
// Name says what asked for the job: a stage, a state, a tool, an
// agent's turn; an item of a list adds its position, and a hook's job
// the hook's name.
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"`
// Meta is data the job's hooks read, and nothing else does.
Meta any `json:"meta,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"`
// Tool is what a hook reads of an agent's tool call as job.tool.
Tool any `json:"tool,omitzero"`
// Hook names the hook the job is. Above says a machine above declares
// it, whose script or machine is in that machine's definition, and Level
// which machine, the nearest being 0. Only the controller sets them.
Hook string `json:"hook,omitzero"`
Above bool `json:"above,omitzero"`
Level int `json:"level,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, a machine, which the controller starts as a child run or, named by its location, as a run of its own, or a send.
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"`
// Meta is data the job's hooks read, and nothing else does.
Meta any `json:"meta,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) 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) MachineAt ¶ added in v0.20.0
func (p *Parser) MachineAt(place, at string) *Definition
MachineAt reads the machine at a location of the tree being read, as a tool that calls it needs it: its type, description, input in full form and lifetime, and nothing else. Its includes are joined, and no machine or tool it names is read, so two machines that name each other are read once each. The location is written out, from the tree's prefix, or in full from /, which no tree read gives: it gives nil, and the run reads that machine as it starts. Where there is no such machine it notes the problem at the place, and gives nil.
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 PlacedSend ¶ added in v0.18.0
type PlacedSend struct {
Place string
To *AddressSpec
// Event is the name of the event sent, and empty for a call.
Event string
// Job is the send or call job, and nil for a chart's send action.
Job *JobSpec
}
A PlacedSend is a send or a call a definition writes, with its place: a send job, a call job or a chart's send action.
func Sends ¶ added in v0.18.0
func Sends(def *Definition) []PlacedSend
Sends gives every send and call a definition writes, in the order the check visits them. Its child definitions are not read.
type Problem ¶
type Problem struct {
File string `json:"file,omitzero"`
Line int `json:"line,omitzero"`
Place string `json:"place"`
Text string `json:"text"`
}
A Problem is one thing wrong with a definition: in which file, at which line, 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. Line is 0 where no written value is near the place, as in a stored definition.
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 marked for approval, which needs a hook before it 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
// Calls gives the locations, each a full path, whose recorded machines
// a run of the definition reads at its first step.
Calls(def *Definition) []string
}
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 Recorded ¶ added in v0.26.0
type Recorded struct {
Description string `json:"description,omitzero"`
Input map[string]any `json:"input,omitzero"`
Type string `json:"type,omitzero"`
Lifetime string `json:"lifetime,omitzero"`
Refused string `json:"refused,omitzero"`
}
Recorded is what a run read at its first step of the machine recorded at a location: its description, its input, its type and its lifetime, or, where a call from the run would not pass, why.
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
type Run struct {
ID string
Location string
Key *string
Context string
Tree string
// Principal is the principal a client started the run for, where the client
// named one.
Principal string
Values map[string]string
// Recorded is what the run read at its first step of the machines
// recorded at the locations its definition calls, by location.
Recorded map[string]Recorded
}
A Run is what an expression reads of the run it is in: its ID, its location, its key at a keyed location, the context its client submitted from, the prefix of its tree, 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
What string
Fields []Field
// 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
}
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.
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 Shown ¶ added in v0.21.0
type Shown struct {
// Stages are a flow's stages, each with its status: waiting, running,
// done, failed or skipped.
Stages map[string]string `json:"stages,omitzero"`
// States are a statechart's active states, outermost first.
States []string `json:"states,omitzero"`
// Turn is how many turns an agent has taken.
Turn int `json:"turn,omitzero"`
}
Shown is the state of a run a watcher is shown for each step, beside what its head says. A flow, a statechart and an agent each fill one field.
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
Fields map[string][]string
// 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
}
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.
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 the state a watcher is shown of a run of the type.
Show(state jsontext.Value) Shown
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.
type TypeShape ¶ added in v0.20.0
A TypeShape 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 type and its name and what every type takes, and the shape named as the type is the type's own.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agent is the machine whose tools a model picks: the model is asked what to do, the tools it picks are run, the results go back to it, and this repeats until it answers without asking for a tool.
|
Package agent is the machine whose tools a model picks: the model is asked what to do, the tools it picks are run, the results go back to it, and this repeats until it answers without asking for a tool. |
|
Package flow is the machine whose stages run once each, in an order that follows from the data they pass.
|
Package flow is the machine whose stages run once each, in an order that follows from the data they pass. |
|
Package statechart is the machine that is always in some state and moves between states when events arrive.
|
Package statechart is the machine that is always in some state and moves between states when events arrive. |