machine

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 28 Imported by: 2 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	DefaultKeep    = Duration(7 * 24 * 3600e9)
	DefaultDepth   = 8
	DefaultTimeout = Duration(5 * 60e9)
)

The defaults of a definition that says nothing.

View Source
const (
	Start  = "start"
	Done   = "done"
	Failed = "failed"
	Timer  = "timer"
)

The names of the events Corbie itself sends a machine.

View Source
const (
	StatusError     = "error"
	StatusTimeout   = "timeout"
	StatusDenied    = "denied"
	StatusCancelled = "cancelled"
)

The ways a job fails.

View Source
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.

View Source
const ExprLimit = time.Second

ExprLimit is how long one expression may run.

View Source
const KeyLimit = 256

KeyLimit is how long a key may be, in characters.

View Source
const Parent = "parent"

Parent is where a send to the machine's parent is addressed.

View Source
const RunName = "run"

RunName is the name every expression of every type reads its run by.

View Source
const TitleLimit = 200

TitleLimit is how long a title may be, in characters.

Variables

View Source
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.

View Source
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.

View Source
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: "key", Kind: KindWord, Like: "question:${run.id}", Does: "the key the machine is started with, which names its run among this client's running runs"},
	{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 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.

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 CheckExpr

func CheckExpr(src string, names []string) error

CheckExpr says what is wrong with an expression that may read the names.

func CheckKey added in v0.12.0

func CheckKey(key string) error

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 CheckText

func CheckText(text string, names []string) error

CheckText says what is wrong with the expressions in a text.

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

func Given(files map[string]string) func(string) ([]byte, error)

Given gives a loader of the files handed over with a definition as text, each under the path the definition names it by.

func HasExpr

func HasExpr(text string) bool

HasExpr says whether a text holds an expression.

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 IsOneExpr

func IsOneExpr(text string) bool

IsOneExpr says whether a text is exactly one expression.

func JobName

func JobName(name string, asked, attempt int) string

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 OneExpr added in v0.2.0

func OneExpr(text string) (string, bool)

OneExpr gives the source of a text that is exactly one expression.

func Register

func Register(t Type)

Register adds a machine type.

func Reserved added in v0.12.0

func Reserved(name string) bool

Reserved says whether a name is one Corbie gives a machine itself, which no client, machine or script can send.

func SendsToKeys added in v0.12.0

func SendsToKeys(def *Definition) bool

SendsToKeys says a definition's type can send an event to a key.

func Types

func Types() []string

Types lists the names of the machine types.

func Written

func Written(src []byte) (map[string]any, error)

Written reads a definition's text into the plain values its reader reads it as: mappings, lists, text, numbers, true and false. It is for a client that shows a person what a definition has written, field by field, as it will be read.

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) 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

func (c *Checker) Asked(ask *JobSpec, check func())

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) Cond

func (c *Checker) Cond(place, src string, names ...string)

Cond checks a condition, which is a bare expression.

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

func (c *Checker) Duration(place, text string, names ...string)

Duration checks a length of time: written out, or with expressions, which may read the names.

func (*Checker) Job

func (c *Checker) Job(place string, s *JobSpec, names ...string)

Job checks a job, whose expressions may read the names.

func (*Checker) Machine added in v0.12.0

func (c *Checker) Machine(place, name string)

Machine checks a machine a send names, which is written out: only a job takes a stored one.

func (*Checker) Name

func (c *Checker) Name(place, name string)

Name checks a name: of a machine, a stage, a state, a tool, a job. An expression in a name is refused.

func (*Checker) Problem

func (c *Checker) Problem(place, format string, args ...any)

Problem notes one thing wrong.

func (*Checker) Value

func (c *Checker) Value(place string, value any, names ...string)

Value checks the expressions in a value, which may read the names.

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; 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"`
	// Meta is data Corbie keeps with the definition and never reads: no
	// expression in it is filled in.
	Meta any `json:"meta,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.

func Load

func Load(ctx context.Context, s store.Store, ref blob.Ref) (*Definition, error)

Load reads a stored definition from the store, as plain JSON: nothing in it is compiled or evaluated. An error that is not ErrDefinition is the store's.

type Description

type Description struct {
	Type   string            `json:"type"`
	Shapes map[string]*Shape `json:"shapes"`
}

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

func Parse(src []byte, load func(path string) ([]byte, error)) (*Draft, error)

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 ParseIn added in v0.12.0

func ParseIn(dir string, src []byte, load func(path string) ([]byte, error)) (*Draft, error)

ParseIn is Parse for a definition in a directory of the context. load gives a file by its path from the context.

func ParseMade

func ParseMade(src []byte, load func(path string) ([]byte, error)) (*Draft, error)

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) Store

func (d *Draft) Store(ctx context.Context, s store.Store, ctl, instance string) (blob.Ref, error)

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) 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.

type Duration

type Duration time.Duration

A Duration is a length of time as definitions write it: 90s, 5m, 48h, 7d.

func ParseDuration

func ParseDuration(text string) (Duration, error)

ParseDuration reads a length of time.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type Ending

type Ending struct {
	Output any    `json:"output,omitzero"`
	Error  *Error `json:"error,omitzero"`
}

An Ending is a machine reaching an end of its own.

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

func Unhandled(job string, data any) *Error

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.

func (*Error) Value

func (e *Error) Value() any

Value is the error as the data of a failed event.

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

func NewEvaluator(at time.Time, seed []byte, run Run) *Evaluator

NewEvaluator makes the evaluator of a step.

func (*Evaluator) Cond

func (e *Evaluator) Cond(src string, scope Scope, place string) (bool, error)

Cond says whether a condition, a bare expression, holds.

func (*Evaluator) Duration added in v0.7.0

func (e *Evaluator) Duration(text string, scope Scope, place string) (Duration, error)

Duration fills in a length of time from a scope's names. Empty text gives none.

func (*Evaluator) Entry

func (e *Evaluator) Entry(entry string, scope Scope, place string) (string, error)

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) Eval

func (e *Evaluator) Eval(src string, scope Scope) (any, error)

Eval gives the value of one expression in a scope.

func (*Evaluator) Fill

func (e *Evaluator) Fill(value any, scope Scope, place string) (any, error)

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

func (e *Evaluator) Key(text string, scope Scope, place string) (string, error)

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.

func (*Evaluator) Text

func (e *Evaluator) Text(text string, scope Scope, place string) (any, error)

Text fills in one text: the value of its one expression, or text with the values of its expressions in it.

func (*Evaluator) Title added in v0.14.0

func (e *Evaluator) Title(text string, scope Scope, place string) (string, error)

Title fills in a title as a key is filled in, and makes it one line of at most TitleLimit characters: each run of white space becomes one space, and the rest is cut.

type Event

type Event struct {
	Name string `json:"name"`
	From string `json:"from,omitzero"`
	Data any    `json:"data,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:"-"`
	// 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

func (f *Field) Holds() *Shape

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

func (f Field) MarshalJSON() ([]byte, error)

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) Bool

func (f *Fields) Bool(name string) bool

Bool takes a field that is true or false.

func (*Fields) Cond added in v0.2.0

func (f *Fields) Cond(name string) string

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) Duration

func (f *Fields) Duration(name string) Duration

Duration takes a field that is a length of time.

func (*Fields) Fields

func (f *Fields) Fields(name string) *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) Has

func (f *Fields) Has(name string) bool

Has says whether the field is written, without taking it.

func (*Fields) Int

func (f *Fields) Int(name string) int

Int takes a field that is a whole number.

func (*Fields) Map

func (f *Fields) Map(name string) (map[string]any, []string)

Map takes a field that is a mapping, and gives its names in order.

func (*Fields) Of

func (f *Fields) Of(name string) *Shape

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) Place

func (f *Fields) Place() string

Place is where in the definition the mapping is.

func (*Fields) Rest

func (f *Fields) Rest() map[string]any

Rest gives the fields not yet taken, for a type to read.

func (*Fields) Size

func (f *Fields) Size(name string) int64

Size takes a field that is a size in bytes, written like 256MB.

func (*Fields) Strings

func (f *Fields) Strings(name string) []string

Strings takes a field that is a list of texts; one text alone is a list of one.

func (*Fields) Text

func (f *Fields) Text(name string) string

Text takes a field that is text.

func (*Fields) Value

func (f *Fields) Value(name string) (any, bool)

Value takes a field that may hold anything: a value, or a job as it is written.

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"`

	// RunKey is the key a machine is started with.
	RunKey *string `json:"key,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.

func (*Job) IsMachine

func (r *Job) IsMachine() bool

IsMachine says whether the job is a machine, started 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
	Key     string   `json:"key,omitzero"`     // the key a machine is started with: text, or expressions
	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) Fill

func (s *JobSpec) Fill(e *Evaluator, scope Scope, place, name string) (*Job, error)

Fill gives the job with its values filled in from a scope.

func (*JobSpec) IsMachine

func (s *JobSpec) IsMachine() bool

IsMachine says whether the job is a machine.

type KeySender added in v0.12.0

type KeySender interface {
	SendsToKeys()
}

A KeySender is a type whose definitions can send an event to a key.

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 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 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) Ask added in v0.12.0

func (p *Parser) Ask(place string, s *JobSpec)

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

func (p *Parser) Builtin(name, source string)

Builtin adds a script that comes with Corbie to the definition's files, under a name no path can have.

func (*Parser) Fields

func (p *Parser) Fields(place string, v any, shape *Shape) *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

func (p *Parser) Job(place string, written any) *JobSpec

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

func (p *Parser) Limits() *Fields

Limits gives the definition's limits, for a type to read those it adds.

func (*Parser) Machine added in v0.12.0

func (p *Parser) Machine(place string, written any) (name string)

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

func (p *Parser) MachineType(name string) string

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.

func (*Parser) Nearer added in v0.12.0

func (p *Parser) Nearer(read func())

Nearer reads jobs that go to an ask nearer than the definition's. A machine that only such jobs run takes that ask as the nearest above it, and needs none from the definition.

func (*Parser) Problem

func (p *Parser) Problem(place, format string, args ...any)

Problem notes one thing wrong, at a place in the file being read.

type PlacedJob added in v0.7.0

type PlacedJob struct {
	Place string
	Job   *JobSpec
}

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.

func (Problem) String

func (p Problem) String() string

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.

func (Problems) Error

func (ps Problems) Error() string

type Read

type Read struct {
	Name string
	Part string
}

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

func Reads(text, root string) []Read

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 "*".

func ReadsIn

func ReadsIn(value any, root string) []Read

ReadsIn lists what every expression in a value reads of a scope's name.

func ReadsOf

func ReadsOf(src, root string) []Read

ReadsOf is Reads for one bare expression.

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 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

func (r *Restart) Wait(doubled int, up time.Duration) (time.Duration, int)

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
	Key     string
	Context string
}

A Run is what an expression reads of the run it is in: its ID, its key if it has one, and the context its client submitted from.

type Scope

type Scope map[string]any

A Scope is what the expressions of one place read, by name.

type Send

type Send struct {
	To string `json:"to,omitzero"` // "parent", or the name of the job that started the child
	// Key names the run it is sent to, in place of To, and Machine is the
	// machine started with that key when no run has it, by its name in the
	// definition.
	Key     *string `json:"key,omitzero"`
	Machine string  `json:"machine,omitzero"`
	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 the run a key names.

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.

func (*Shape) Sort

func (s *Shape) Sort(written map[string]any) string

Sort says which sort of thing a written mapping of the shape is: the value of the field that says so, or what follows from the rest. It is nothing for a shape that has no sorts, and for a mapping that says nothing of its sort.

type ShortForm added in v0.8.0

type ShortForm struct {
	Blob   map[string]any
	Closed bool
}

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.

func (ShortForm) Full added in v0.8.0

func (sf ShortForm) Full(shape map[string]any) (map[string]any, error)

Full gives a shape in full form. A short form that names a type there is not is refused, saying so.

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 TimerAt

type TimerAt struct {
	Name string    `json:"name"`
	At   time.Time `json:"at"`
}

TimerAt asks for a timer event at a time.

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.

func TypeOf

func TypeOf(name string) (Type, bool)

TypeOf gives the machine type of a name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL