progress

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 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 progress writes and reads the progress stream that a long-running ocfp command produces, one JSON object per line.

Index

Constants

View Source
const WireContract = 1

WireContract is the version of the progress stream format. A reader compares the header's wireContract with this value before it trusts the rest of the stream.

Variables

View Source
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")
)

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock supplies the time stamped on each record.

func SystemClock

func SystemClock() Clock

SystemClock returns a Clock backed by the wall clock.

type Code

type Code string

Code is a stable, machine-readable name for a refusal or failure.

const CodeOwnerRecordMissing Code = "OWNER_RECORD_MISSING"

CodeOwnerRecordMissing reports that the host has no owner record.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads records from a stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a Decoder that reads from r.

func (*Decoder) Decode

func (d *Decoder) Decode() (Record, error)

Decode returns the next record after the header. When the header has not been read yet, Decode reads and checks it first, so a stream without a header is refused with ErrNoHeader. At the end of the stream it returns io.EOF.

func (*Decoder) Header

func (d *Decoder) Header() (Header, error)

Header reads the first record and returns its header body. It returns ErrNoHeader when the stream is empty or begins with another kind of record.

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

func NewEncoder(w io.Writer, c Clock) *Encoder

NewEncoder returns an Encoder that writes to w and stamps records from c.

func (*Encoder) Encode

func (e *Encoder) Encode(kind Kind, body any) error

Encode writes one record of the given kind. It returns ErrHeaderFirst until Header has been called.

func (*Encoder) Header

func (e *Encoder) Header(h Header) error

Header writes the header record, which carries seq 0. The WireContract field is always set to the current WireContract.

type ErrorBody

type ErrorBody struct {
	Code    Code   `json:"code"`
	Message string `json:"message"`
}

ErrorBody is the body of an error record.

type Header struct {
	WireContract int    `json:"wireContract"`
	Producer     string `json:"producer"`
	Version      string `json:"version"`
	JobID        string `json:"jobId,omitempty"`
}

Header is the body of the first record. It names the producer and the wire contract the rest of the stream follows.

type Kind

type Kind string

Kind names the type of a record in the stream.

const (
	KindHeader   Kind = "header"
	KindEvent    Kind = "event"
	KindQuestion Kind = "question"
	KindLog      Kind = "log"
	KindResult   Kind = "result"
	KindError    Kind = "error"
)

The record kinds. The first record of every stream is a header.

type LogBody

type LogBody struct {
	Stream string `json:"stream"`
	Line   string `json:"line"`
}

LogBody is the body of a log record.

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 ResultBody

type ResultBody struct {
	ExitCode int `json:"exitCode"`
}

ResultBody is the body of the final record of a stream.

Directories

Path Synopsis
Package progresstest holds golden progress streams for tests.
Package progresstest holds golden progress streams for tests.

Jump to

Keyboard shortcuts

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