Documentation
¶
Overview ¶
Package instance is the two things an instance is in the store: its head, which says where it stands, and its record, which is everything that happened to it; and the messages and receipts that pass between a client and the controller about it.
Index ¶
- Constants
- type Above
- type Answer
- type Arrived
- type Ask
- type AskAbove
- type CallReceipt
- type CallResult
- type Emit
- type EmitNote
- type Emitted
- type Going
- type Head
- type Heard
- type Job
- type KeyFile
- type Message
- type Receipt
- type Recorded
- type Result
- type Start
- type State
- type Step
- func Current(ctx context.Context, s store.Store, ctl identity.Card, id *identity.Identity, ...) (*Step, error)
- func Latest(ctx context.Context, s store.Store, ctl identity.Card, id *identity.Identity, ...) (*Step, error)
- func ReadStep(ctx context.Context, s store.Store, ctl identity.Card, id *identity.Identity, ...) (*Step, error)
- type Submit
- type SubmitFile
- type Submitted
- type Ticket
- type Timer
Constants ¶
const ( Waiting = "waiting" Running = "running" Done = "done" Failed = "failed" Cancelled = "cancelled" )
The words for where an instance stands. A run that has been sent and not yet taken up is waiting; it has no head.
const ( AskScript = "script" // send a script to a runner AskChild = "child" // start a child machine AskCall = "call" // start a run at a location for a call job AskCancel = "cancel" // cancel a job AskEvent = "event" // send an event to the parent or a child AskWake = "wake" // be woken at a time AskReceipt = "receipt" // answer a client's message AskResult = "result" // write what became of a run a client called, beside the call's receipt AskEnd = "end" // tell the parent the instance has ended AskFail = "fail" // a job failed before anything was sent AskHold = "hold" // a job is held for the ask AskNote = "note" // something to be seen in the record AskTell = "tell" // a note for the record of the run that started this one )
The kinds of thing a step asks for.
const ( EmitLog = "log" EmitProgress = "progress" )
The names of the emits Corbie itself gives a script.
const ( KindSubmit = "submit" // record a tree at a prefix KindStart = "start" // start a run KindCancel = "cancel" // cancel a run; to a runner, cancel a job KindEvent = "event" // send a run an event KindAnswer = "answer" // answer a ticket KindResult = "result" // a job's outcome: a script's from its runner, a child's from the controller KindEmit = "emit" // a value a job sent up that the machine wants KindJob = "job" // a job for a runner KindSend = "send" // an event sent to an address, with what starts a run for it if there is one KindNote = "note" // something to be written in a run's record )
The kinds of message.
const AskName = "ask"
AskName is the name of the job that gives the yes when a job needs approval. Nothing else in a definition may take it.
const MaxHeard = 64
MaxHeard is how many senders an instance remembers the last message of.
const MessageLife = 5 * time.Minute
MessageLife is how long a message is good for when its sender says nothing.
const ReceiptLife = 24 * time.Hour
ReceiptLife is how long a receipt is kept, and a call's receipt and result after the result is written.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Above ¶
type Above struct {
Parent string `json:"parent,omitzero"` // the instance that started it
Job string `json:"job,omitzero"` // the job of the parent's that it is
Depth int `json:"depth,omitzero"` // how many machines are above it
// MaxDepth is how many levels the root allows below itself.
MaxDepth int `json:"max_depth,omitzero"`
// Layers are the permissions that narrow it: the start's own list, and
// the job of each parent that led to it.
Layers []permission.Layer `json:"layers,omitzero"`
// Approve are the lists, from the machines above, of permissions a job
// may use only after a yes.
Approve []string `json:"approve,omitzero"`
// Ask is the nearest ask above, for a machine that has none of its own.
Ask *AskAbove `json:"ask,omitzero"`
// IsAsk says the instance is itself run as an ask.
IsAsk bool `json:"is_ask,omitzero"`
// Made says a machine above it, or the instance itself, was made while
// running: its job gave a stored definition. The controller sets it when
// it starts a child, and a definition has no say in it.
Made bool `json:"made,omitzero"`
// Context is the directory last submitted at the run's tree.
Context string `json:"context,omitzero"`
// Values are the values set at the root's location or above, as they
// were at the root's first step, by name. A run a send or a call
// started takes those of its own location, never its sender's.
Values map[string]string `json:"values,omitzero"`
// Keep is the longest the instance may be kept after it ends: no
// longer than what started it, so a child's record goes no later than
// its parent's.
Keep machine.Duration `json:"keep,omitzero"`
// StartedBy is the run whose send or call started the instance. It is
// a root of its own tree's client, and no parent of it.
StartedBy string `json:"started_by,omitzero"`
// CallJob is, for a run a call job started, that job of StartedBy's:
// the run's end is the job's result.
CallJob string `json:"call_job,omitzero"`
// CallReceipt is, for a run a client called in a tree it does not own,
// the call's message: the run's result is written beside its receipt.
CallReceipt *CallReceipt `json:"call_receipt,omitzero"`
}
Above is what an instance was started under: who started it and the limits that came with the start.
type Arrived ¶
type Arrived struct {
machine.Event
Source string `json:"source,omitzero"`
Own bool `json:"own,omitzero"`
}
Arrived is an event with the message or wake it came from. Machine says whether it was given to the machine or was the controller's own to act on.
type Ask ¶
type Ask struct {
Kind string `json:"kind"`
// Name is the job a script, a child, a cancel or a failure is about.
Name string `json:"name,omitzero"`
Job *machine.Job `json:"job,omitzero"`
// Attempt is which attempt at the job this is.
Attempt int `json:"attempt,omitzero"`
Runner string `json:"runner,omitzero"`
// Card is the card of the runner a job goes to: what that job adds to
// the record is checked against it.
Card identity.Card `json:"card,omitzero"`
Child string `json:"child,omitzero"`
// To is the instance an event is sent to; none for an event a root
// sends up, which is only written here.
To string `json:"to,omitzero"`
Event *machine.Event `json:"event,omitzero"`
// Location is the location an event is sent to or a call starts a run
// at. Key is the key an event is sent to, and Run the run it is started
// as when no run has the key, or the run a call starts.
Location string `json:"location,omitzero"`
Key string `json:"key,omitzero"`
Run string `json:"run,omitzero"`
// Client is the client an event was addressed to, which has no inbox.
Client string `json:"client,omitzero"`
// Direct says the event was sent to one run by its ID, which is To.
Direct bool `json:"direct,omitzero"`
// Undelivered says the event was for a child that is not running, or
// for an address that names no running run able to take it.
Undelivered bool `json:"undelivered,omitzero"`
// At is a wake's time, or a job's due time.
At time.Time `json:"at,omitzero"`
What string `json:"what,omitzero"` // what a wake is for
// Message is the name of the message, in an inbox, that carrying this
// out writes.
Message string `json:"message,omitzero"`
Sender string `json:"sender,omitzero"` // whose message a receipt or a call's result answers
Receipt *Receipt `json:"receipt,omitzero"`
Result *CallResult `json:"result,omitzero"`
Error *machine.Error `json:"error,omitzero"`
Output any `json:"output,omitzero"`
Text string `json:"text,omitzero"`
}
An Ask is one thing a step asked for.
type AskAbove ¶
type AskAbove struct {
Spec *machine.JobSpec `json:"spec"`
At string `json:"at"`
Definition blob.Ref `json:"definition"`
Input any `json:"input,omitzero"`
Layers []permission.Layer `json:"layers,omitzero"`
}
AskAbove is an ask a machine takes from above: the ask as written, where it is written, the definition that declares it and the input its values are filled from. No machine made while running declares one.
type CallReceipt ¶ added in v0.17.0
A CallReceipt names a client's call: the client and its message.
type CallResult ¶ added in v0.17.0
type CallResult struct {
Status string `json:"status"`
Output any `json:"output,omitzero"`
Error *machine.Error `json:"error,omitzero"`
}
A CallResult is what became of a run a client called in a tree it does not own, written beside the call's receipt when the run ends: its status, and its output or error. The blobs its output names are beside it.
type Emit ¶
type Emit struct {
Job string `json:"job"` // the job that emitted
Number int `json:"number"` // which of the job's emit entries it is, counted from one
Values []Emitted `json:"values"`
}
An Emit is one emit entry of a record: values a job emitted, in the order it made them, written by the job's runner.
type EmitNote ¶
type EmitNote struct {
Job string `json:"job"`
Name string `json:"name"`
Index int `json:"index"`
Data any `json:"data,omitzero"`
}
An EmitNote tells the controller of a value a job sent up that the machine wants to act on. Index is which value of that name it is from that job, counting from one.
type Emitted ¶
type Emitted struct {
Name string `json:"name"`
Data any `json:"data,omitzero"`
At time.Time `json:"at"`
}
Emitted is one value a job emitted while it ran: a log line, a note of progress, a named value.
type Going ¶
type Going struct {
machine.Job
Asked int `json:"asked"` // which time its name asked for a job
Attempt int `json:"attempt"` // which attempt this is
// Runner is the runner a job was sent to.
Runner string `json:"runner,omitzero"`
// Child is the instance a machine was started as.
Child string `json:"child,omitzero"`
// Called is the run a call job started.
Called string `json:"called,omitzero"`
// Due is when a job's result is due.
Due time.Time `json:"due,omitzero"`
// Began is when this attempt was sent on its way.
Began time.Time `json:"began,omitzero"`
// Again is when the job restarts.
Again time.Time `json:"again,omitzero"`
// Anew says the job ended well and restarts as a new job.
Anew bool `json:"anew,omitzero"`
// Restarts is how many times the job has restarted, and Restarted when,
// for a limit in a length of time.
Restarts int `json:"restarts,omitzero"`
Restarted []time.Time `json:"restarted,omitzero"`
// Doubled is how many times its delay has doubled.
Doubled int `json:"doubled,omitzero"`
// Wake is what the job's wake, for its due time or its next attempt,
// is called.
Wake string `json:"wake,omitzero"`
// Held says the job waits for the ask before it starts.
Held bool `json:"held,omitzero"`
// ForAsk lists the held jobs this job of the ask is deciding.
ForAsk []string `json:"for_ask,omitzero"`
}
A Going is a job still going.
type Head ¶
type Head struct {
Name string `json:"name"` // the instance
Machine string `json:"machine"` // what the definition is called
Type string `json:"type"`
Status string `json:"status"`
// Failure says how a failed instance failed: error, timeout or denied.
Failure string `json:"failure,omitzero"`
Step int `json:"step"`
Started time.Time `json:"started"`
Ended time.Time `json:"ended,omitzero"`
Parent string `json:"parent,omitzero"`
// Location is where the run's machine lives, Key is its key at a keyed
// location, and StartedBy is the run whose send or call started it.
Location string `json:"location,omitzero"`
Key string `json:"key,omitzero"`
StartedBy string `json:"started_by,omitzero"`
Jobs int `json:"jobs,omitzero"`
Timers int `json:"timers,omitzero"`
Tickets []string `json:"tickets,omitzero"`
Labels map[string]string `json:"labels,omitzero"`
// Keep is how long the instance is kept after it ends.
Keep machine.Duration `json:"keep,omitzero"`
}
A Head is the small public summary of an instance, signed by the controller and sealed to nobody. Apart from its location, key and labels it holds nothing the instance was given or produced.
func ReadHead ¶
func ReadHead(ctx context.Context, s store.Store, ctl identity.Card, name string) (*Head, store.Mark, error)
ReadHead reads an instance's head, wherever it is. An instance whose head is among the finished has ended, also when a head is still among the running. A head that moves between the two looks is found.
type Job ¶
type Job struct {
Instance string `json:"instance"`
Name string `json:"name"` // the job's full name, its attempt included
Attempt int `json:"attempt"`
// Request names what asked: every attempt at the same job has the same.
Request string `json:"request"`
Script blob.Ref `json:"script"`
// Path is the script's path as the definition names it, and none for
// a stored script. Files are keyed the same way.
Path string `json:"path,omitzero"`
Files map[string]blob.Ref `json:"files,omitzero"`
Input any `json:"input,omitzero"`
// Layers are every layer of permissions that applies, each by name.
Layers []permission.Layer `json:"layers"`
// Secrets are the values of the secrets the job names.
Secrets map[string]string `json:"secrets,omitzero"`
Timeout machine.Duration `json:"timeout"`
Memory int64 `json:"memory,omitzero"`
// Due is when the job's result is due.
Due time.Time `json:"due"`
// Wants names the emitted values the machine wants to hear about.
Wants []string `json:"wants,omitzero"`
// Client is the card of the client that owns the root's tree: what the
// job adds to the record is sealed to it and to the controller.
Client identity.Card `json:"client"`
}
A Job is everything a runner needs to run a script: with the job and the store, and nothing else from the controller, the runner can run it.
type KeyFile ¶ added in v0.12.0
A KeyFile says which run a key names, and which message starts that run.
func ReadKey ¶ added in v0.12.0
func ReadKey(ctx context.Context, s store.Store, ctl identity.Card, id *identity.Identity, at, key string) (*KeyFile, store.Mark, error)
ReadKey reads the file of a key, under its name at. It gives nil where there is none. A file that does not check gives an error, and its mark.
type Message ¶
type Message struct {
Kind string `json:"kind"`
// Instance is the instance the message is for.
Instance string `json:"instance,omitzero"`
// From is, in a message the controller sends itself, the instance it
// is sent on behalf of.
From string `json:"from,omitzero"`
// To is the address an event is sent to or a call starts a run at, and
// Sender the run or client it is from. Only the controller writes
// Sender.
To *machine.Address `json:"to,omitzero"`
Sender *machine.Address `json:"sender,omitzero"`
Start *Start `json:"start,omitzero"`
Submit *Submit `json:"submit,omitzero"`
Event *machine.Event `json:"event,omitzero"`
Answer *Answer `json:"answer,omitzero"`
Result *Result `json:"result,omitzero"`
Emit *EmitNote `json:"emit,omitzero"`
Job *Job `json:"job,omitzero"`
Note string `json:"note,omitzero"`
// Cancel names, for a runner, the job that is cancelled.
Cancel string `json:"cancel,omitzero"`
}
A Message is what one party leaves in another's inbox. Kind says which of the parts it carries.
type Receipt ¶
type Receipt struct {
Taken bool `json:"taken"`
Refused string `json:"refused,omitzero"`
// Denied is a start a permission refused, as a run's failure gives it:
// what was refused, the layer that refused it and the fix.
Denied *machine.Error `json:"denied,omitzero"`
// Problems are what is wrong with a definition that was refused.
Problems machine.Problems `json:"problems,omitzero"`
// Tree is what a submit that was taken did.
Tree *Submitted `json:"tree,omitzero"`
// Acted says, for an event, whether the machine acted on it or had no
// rule for it.
Acted *bool `json:"acted,omitzero"`
// Run is, for an event sent to an address, the run that took it.
Run string `json:"run,omitzero"`
}
A Receipt is the controller's answer to one message of a client's: that it was taken, or why it was refused.
type Recorded ¶ added in v0.17.0
type Recorded struct {
Location string `json:"location"`
Lifetime string `json:"lifetime,omitzero"`
What string `json:"what"`
Run string `json:"run,omitzero"`
}
Recorded is what a submit did at one location: started, restarted, recorded, removed or problem. Run is the run it started.
type Result ¶
type Result struct {
Job string `json:"job"` // the job, as its instance's step named it
Attempt int `json:"attempt,omitzero"`
// Status is done, or one of the ways a job fails.
Status string `json:"status"`
Output any `json:"output,omitzero"`
Error *machine.Error `json:"error,omitzero"`
// Used lists the permissions a job used.
Used []string `json:"used,omitzero"`
// Final says a failure is not to be tried again.
Final bool `json:"final,omitzero"`
}
A Result is how a job ended.
type Start ¶
type Start struct {
Definition blob.Ref `json:"definition,omitzero"`
Input any `json:"input,omitzero"`
InputBlob blob.Ref `json:"input_blob,omitzero"`
Labels map[string]string `json:"labels,omitzero"`
// Allow is the start's own list, which narrows the root and everything
// below it.
Allow *permission.Layer `json:"allow,omitzero"`
// Timeout is how long the run may take, if the start says.
Timeout machine.Duration `json:"timeout,omitzero"`
// Seed is the secret the instance's tickets and random numbers follow
// from.
Seed []byte `json:"seed"`
// Above is set by the controller when it starts a child.
Above *Above `json:"above,omitzero"`
// Location is the location the run is started at: its machine is the
// file recorded there.
Location string `json:"location,omitzero"`
// Key is, for an event sent to a key, the key of the run it starts.
Key string `json:"key,omitzero"`
// Tree is the prefix of the tree the location is in, for a child, which
// runs at its parent's location.
Tree string `json:"tree,omitzero"`
// Replaces is, for a singleton a submit starts again, the runs it
// replaces: the new run starts once every one has ended.
Replaces []string `json:"replaces,omitzero"`
// Run is the run an event sent to a key starts, where it names one: the
// event's data is its input. What a client or a job starts is the
// message's own instance.
Run string `json:"run,omitzero"`
}
A Start starts a run. A client's start names a location, and its input is the blob InputBlob in the run's record; Definition and Input are written by the controller, from the file recorded there and that blob, or from the job that starts a child.
type State ¶
type State struct {
Machine string `json:"machine"`
Type string `json:"type"`
Status string `json:"status"`
Output any `json:"output,omitzero"`
Error *machine.Error `json:"error,omitzero"`
Started time.Time `json:"started"`
Ended time.Time `json:"ended,omitzero"`
Definition blob.Ref `json:"definition"`
Input any `json:"input,omitzero"`
Labels map[string]string `json:"labels,omitzero"`
// Location is where the instance's machine lives: the location of the
// file it was started from, or of the run that started it as a child.
// Tree is the prefix of the tree that location is in.
Location string `json:"location,omitzero"`
Tree string `json:"tree,omitzero"`
// Key is the instance's key at a keyed location, while it runs.
Key string `json:"key,omitzero"`
// Lifetime is the lifetime of the file a root was started from at its
// location. A child has none.
Lifetime string `json:"lifetime,omitzero"`
// Title is what the definition's title filled in to when the instance
// started.
Title string `json:"title,omitzero"`
// Seed is the instance's own secret: its keys and random numbers follow
// from it.
Seed []byte `json:"seed"`
// Keep is how long the instance is kept after it ends.
Keep machine.Duration `json:"keep,omitzero"`
// Ask is the ask its definition names, for what it starts.
Ask *machine.JobSpec `json:"ask,omitzero"`
// Above is what the instance was started under.
Above Above `json:"above"`
// TimeoutAt is when the instance passes its timeout, if it has one.
TimeoutAt time.Time `json:"timeout_at,omitzero"`
// Inner is the machine type's own state.
Inner jsontext.Value `json:"inner,omitzero"`
// Jobs are the jobs still going, by the name that asked for them.
Jobs map[string]*Going `json:"jobs,omitzero"`
// Timers are the timers set, by name.
Timers map[string]Timer `json:"timers,omitzero"`
// Tickets are the tickets waited on, by the id the machine gave each.
Tickets map[string]Ticket `json:"tickets,omitzero"`
// Asked counts how many times each name has asked for a job.
Asked map[string]int `json:"asked,omitzero"`
// JobsStarted counts the jobs the instance has started.
JobsStarted int `json:"jobs_started,omitzero"`
// Heard is the name of the last message taken from each of the most
// recent MaxHeard senders, oldest first: the instance's parent and each
// run that sent to it by address. The controller writes those under
// names that sort in the order sent, and may write one again when it
// repeats a carry-out: one that does not sort after the last taken from
// its sender has been taken already.
Heard []Heard `json:"heard,omitzero"`
// Emitted counts, for each job and name, the values of its attempt
// given to the machine, so one that arrives twice is given once.
Emitted map[string]int `json:"emitted,omitzero"`
// Sent counts the events the instance has sent up to its parent.
Sent int `json:"sent,omitzero"`
// Used lists the permissions used by every job in the instance and
// below it.
Used []string `json:"used,omitzero"`
// Answered remembers, by a short mark, the last few tickets answered, so a
// second answer can be told it came second.
Answered []string `json:"answered,omitzero"`
}
State is everything about an instance that is not its history.
type Step ¶
type Step struct {
Number int `json:"number"`
Time time.Time `json:"time"`
// Events are what arrived, in the order they were taken.
Events []Arrived `json:"events,omitzero"`
// Used names every message and wake the step used. They are deleted
// only when the step has been carried out.
Used []string `json:"used,omitzero"`
State State `json:"state"`
// Asks are what the step asked for, each under a name the entry fixes.
Asks []Ask `json:"asks,omitzero"`
}
A Step is one step entry of a record: the events that arrived and what they came from, the state the instance was left in, and what the step asked for. The latest step is the instance's whole state.
func Current ¶
func Current(ctx context.Context, s store.Store, ctl identity.Card, id *identity.Identity, name string) (*Step, error)
Current gives an instance's latest step, found from its head. Older steps may have been trimmed, so reading always starts from the number the head gives. It gives nil where the instance has no head.
type Submit ¶ added in v0.17.0
type Submit struct {
Prefix string `json:"prefix"`
Directory string `json:"directory"`
Files map[string]SubmitFile `json:"files,omitzero"`
Problems []string `json:"problems,omitzero"`
}
A Submit records a directory as a tree at a prefix. Files are its machines, by location, each uploaded with the message; Problems are the locations of files that could not be read, which keep what was recorded before.
type SubmitFile ¶ added in v0.17.0
type SubmitFile struct {
Definition blob.Ref `json:"definition"`
Hash string `json:"hash"`
Secrets []string `json:"secrets,omitzero"`
Values []string `json:"values,omitzero"`
}
A SubmitFile is one machine of a submit: its stored definition among the message's uploads, the hash of what it runs, and the names of the secrets and the values it uses.
type Submitted ¶ added in v0.17.0
type Submitted struct {
Locations []Recorded `json:"locations,omitzero"`
Cancelled []string `json:"cancelled,omitzero"`
Before string `json:"before,omitzero"`
Missing []string `json:"missing,omitzero"`
}
Submitted is what a submit did: what became of each location of the tree, the runs it cancelled, the directory last submitted there when it was another, and the secrets and values the files use that are not set.