Documentation
¶
Overview ¶
Package progress writes and reads the progress stream that a long-running ocfp command produces, one JSON object per line.
Index ¶
- Constants
- Variables
- type AnswerSource
- type Artifact
- type CancelOutcome
- type Clock
- type Code
- type Decoder
- type Encoder
- type ErrorBody
- type Event
- type EventKind
- type Header
- type Kind
- type LogBody
- type Prompter
- type Question
- type QuestionKind
- type Record
- type Refusal
- type ResultBody
- type Sink
- type UndoState
- type UndoneWork
- type WorkRef
Constants ¶
const WireContract = 3
WireContract is the version of the progress stream format and of the job request that asks for it. A reader compares the header's wireContract with this value before it trusts the rest of the stream. Contract 2 added the org and the bloc to the job request. Contract 3 added the request's action, the cancel budget in the header, and the cancel outcome in the result.
Variables ¶
var ( // ErrHeaderFirst is returned when Encode runs before Header. ErrHeaderFirst = errors.New("progress: the header must be written first") // ErrNoHeader is returned when a stream does not begin with a header record. ErrNoHeader = errors.New("progress: stream does not begin with a header record") )
var ErrAnswerTooLong = errors.New("progress: answer line is too long")
ErrAnswerTooLong is returned when an answer line passes the length limit.
var ErrNoAnswerNonInteractive = errors.New("progress: question has no default and the run is not interactive")
ErrNoAnswerNonInteractive is returned when a run is not interactive and a question has no default, so nothing could answer it.
Functions ¶
This section is empty.
Types ¶
type AnswerSource ¶ added in v0.5.4
AnswerSource supplies the answer for a question id, blocking until one is available.
type Artifact ¶ added in v0.5.4
type Artifact struct {
Name string `json:"name"`
Path string `json:"path"`
Digest string `json:"digest"`
}
Artifact describes a file that a step produced.
type CancelOutcome ¶ added in v0.5.8
type CancelOutcome string
CancelOutcome says how a cancelled job ended.
const ( // CancelStopped means the verb reached a safe point and stopped. CancelStopped CancelOutcome = "stopped" // CancelKilled means the cancel budget passed and the verb was killed. CancelKilled CancelOutcome = "killed" // CancelAlreadyFinished means the job had ended before the cancel took // effect. CancelAlreadyFinished CancelOutcome = "already_finished" )
The cancel outcomes. A run stores only stopped and killed. A requester derives already_finished from a stream that carries no cancel.
func CancelOutcomeOf ¶ added in v0.5.8
func CancelOutcomeOf(lastError *ErrorBody, res ResultBody) (CancelOutcome, bool)
CancelOutcomeOf is the outcome that a cancel requester reads from the stream it got back, given the stream's last error, if any, and its result. A result whose cancel is stopped or killed gives that outcome. A complete stream with no error and no cancel in its result means the job had already finished. A stream that ends in JOB_ORPHANED or in a refusal, or whose result names a cancel this CLI does not know, has no outcome, and CancelOutcomeOf then reports false.
type Code ¶
type Code string
Code is a stable, machine-readable name for a refusal or failure.
const ( // CodeOwnerRecordMissing reports that the host has no owner record. CodeOwnerRecordMissing Code = "OWNER_RECORD_MISSING" // CodeOwnerMismatch reports a record that names another installation or // epoch. CodeOwnerMismatch Code = "OWNER_MISMATCH" // CodeRequestUnsigned reports a request that the owner's instance key did // not sign. CodeRequestUnsigned Code = "REQUEST_UNSIGNED" // CodeOwnerHandover reports an owner record that is in handover. CodeOwnerHandover Code = "OWNER_HANDOVER" // CodeJobRequestInvalid reports a request that does not parse or whose // issue time falls outside the accepted window. CodeJobRequestInvalid Code = "JOB_REQUEST_INVALID" // CodeVerbNotAllowed reports a verb that the wrapper does not accept. CodeVerbNotAllowed Code = "VERB_NOT_ALLOWED" // CodeWireContractUnsupported reports a wire contract version that the // CLI cannot write. CodeWireContractUnsupported Code = "WIRE_CONTRACT_UNSUPPORTED" // CodeOwnerRecordExists reports a create-only write of an owner record // where one already exists. CodeOwnerRecordExists Code = "OWNER_RECORD_EXISTS" // CodeJobOrphaned reports an attach to a spool whose wrapper died without // writing an exit record. CodeJobOrphaned Code = "JOB_ORPHANED" // CodeOwnerRecordInvalid reports an owner record on the host that does // not parse or does not verify, so that a requester never reads it as a // fault in its own request. CodeOwnerRecordInvalid Code = "OWNER_RECORD_INVALID" // CodeOrgBlocMismatch reports a request, a replacement owner record, or a // proof that gives up the owner record, for an org or a bloc other than // the one the host's owner record names. CodeOrgBlocMismatch Code = "ORG_BLOC_MISMATCH" // CodeJobCancelled reports a job that ended because a cancel asked it to // stop. CodeJobCancelled Code = "JOB_CANCELLED" // CodeJobNotFound reports a cancel of a job that has no spool on the // host. A requester whose own run has not yet made the spool can try // again. CodeJobNotFound Code = "JOB_NOT_FOUND" )
The refusal codes. A code is never renamed once it ships.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads records from a stream.
func NewDecoder ¶
NewDecoder returns a Decoder that reads from r.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes records as lines of JSON. It is safe for concurrent use, and a line is always written whole.
func NewEncoder ¶
NewEncoder returns an Encoder that writes to w and stamps records from c.
type Event ¶ added in v0.5.4
type Event struct {
Kind EventKind `json:"kind"`
Step string `json:"step"`
Message string `json:"message,omitempty"`
Current int64 `json:"current,omitempty"`
Total int64 `json:"total,omitempty"`
Outcome string `json:"outcome,omitempty"`
Artifact *Artifact `json:"artifact,omitempty"`
// Undone lists the work that a cancelled job left undone, because its
// undo hook did not run or failed. Only the warning that a cancelled
// job's stream carries sets it.
Undone []UndoneWork `json:"undone,omitempty"`
}
Event is one structured report of progress from a step.
type EventKind ¶ added in v0.5.4
type EventKind string
EventKind names the type of a progress event.
type Header ¶
type Header struct {
WireContract int `json:"wireContract"`
Producer string `json:"producer"`
Version string `json:"version"`
JobID string `json:"jobId,omitempty"`
// CancelBudgetMs is how long, in whole milliseconds, the verb that runs
// has to stop once a cancel arrives. It is absent from a header that
// names no verb.
CancelBudgetMs int64 `json:"cancelBudgetMs,omitempty"`
}
Header is the body of the first record. It names the producer and the wire contract the rest of the stream follows.
type Prompter ¶ added in v0.5.4
Prompter asks a question and returns the answer.
func NewNDJSONPrompter ¶ added in v0.5.4
func NewNDJSONPrompter(enc *Encoder, src AnswerSource, interactive bool) Prompter
NewNDJSONPrompter returns a Prompter that writes each question as a question record and then waits for src to supply the answer. An answer is never written to the stream. When interactive is false it answers from the default without writing anything, and fails when there is none.
func NewTerminalPrompter ¶ added in v0.5.4
NewTerminalPrompter returns a Prompter that writes questions to out and reads answers from in. When interactive is false it never touches either, answers from the default, and fails when there is none. A sensitive question's default is never printed. The reader is used as given, so a caller that wants hidden input passes a reader that provides it. A terminal prompter is for one goroutine at a time.
type Question ¶ added in v0.5.4
type Question struct {
ID string `json:"id"`
Kind QuestionKind `json:"kind"`
Text string `json:"text"`
Choices []string `json:"choices"`
Default *string `json:"default"`
Sensitive bool `json:"sensitive"`
}
Question is one thing a step needs answered. A confirm answer is "yes" or "no", and a choose answer is one of Choices. Default is nil when the question has none.
type QuestionKind ¶ added in v0.5.4
type QuestionKind string
QuestionKind names the shape of the answer a question expects.
const ( QuestionConfirm QuestionKind = "confirm" QuestionChoose QuestionKind = "choose" QuestionText QuestionKind = "text" )
The question kinds.
type Record ¶
type Record struct {
Kind Kind `json:"kind"`
Seq int64 `json:"seq"`
Time time.Time `json:"time"`
Body json.RawMessage `json:"body"`
}
Record is one line of the stream. Seq is 0 for the header and counts up by one for every record after it.
type Refusal ¶ added in v0.5.4
Refusal is an error that carries a Code, so a caller can act on the reason without matching message text.
type ResultBody ¶
type ResultBody struct {
ExitCode int `json:"exitCode"`
Cancel CancelOutcome `json:"cancel,omitempty"`
}
ResultBody is the body of the final record of a stream. Cancel is set only when a cancel ended the job.
type Sink ¶ added in v0.5.4
Sink receives progress events. An adapter decides how to show them.
func NewNDJSONSink ¶ added in v0.5.4
NewNDJSONSink returns a Sink that writes each event as an event record.
func NewTerminalSink ¶ added in v0.5.4
NewTerminalSink returns a Sink that prints events as readable lines to w.
type UndoState ¶ added in v0.5.8
type UndoState string
UndoState says why a piece of work was left undone.
type UndoneWork ¶ added in v0.5.8
UndoneWork is one piece of work that a job left undone, and why. Its JSON holds the work's kind and id beside the state.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package progresstest holds golden progress streams for tests.
|
Package progresstest holds golden progress streams for tests. |