Back to godoc.org
go.uber.org/tools/lib/parallel

package parallel

v0.0.0 (2cfd321)
Latest Go to latest
Published: Jun 18, 2019 | License: MIT | Module: go.uber.org/tools

Index

Constants

const DefaultFastFail = false

DefaultFastFail is the default value for fast fail.

Variables

var (
	// DefaultMaxConcurrentCmds is the default value for the maximum
	// number of concurrent commands.
	DefaultMaxConcurrentCmds = runtime.NumCPU()
	// DefaultEventHandler is the default Event handler.
	DefaultEventHandler = logEvent
	// DefaultClock is the default function to use as a clock.
	DefaultClock = time.Now
)

type Cmd

type Cmd interface {
	fmt.Stringer

	// Start the command.
	Start() error
	// Wait for the command to complete and block.
	Wait() error
	// Kill the command.
	Kill() error
}

Cmd is a command to run.

func ExecCmd

func ExecCmd(cmd *exec.Cmd) Cmd

ExecCmd returns a new Cmd for the given exec.Cmd.

func ExecCmds

func ExecCmds(cmds []*exec.Cmd) []Cmd

ExecCmds returns a slice of Cmds for the given exec.Cmds.

type Event

type Event struct {
	Type   EventType              `json:"type,omitempty" yaml:"type,omitempty"`
	Time   time.Time              `json:"time,omitempty" yaml:"time,omitempty"`
	Fields map[string]interface{} `json:"fields,omitempty" yaml:"fields,omitempty"`
	Error  string                 `json:"error,omitempty" yaml:"error,omitempty"`
}

Event is an event that happens during the runner's Run call.

type EventType

type EventType int

EventType is an event type during the runner's run call.

const (
	// EventTypeStarted says that the runner started.
	EventTypeStarted EventType = iota + 1
	// EventTypeCmdStarted says that a command started.
	EventTypeCmdStarted
	// EventTypeCmdFinished says that a command finished.
	EventTypeCmdFinished
	// EventTypeFinished says that the runner finished.
	EventTypeFinished
)

func (EventType) MarshalJSON

func (e EventType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the EventType to JSON.

func (EventType) MarshalText

func (e EventType) MarshalText() ([]byte, error)

MarshalText marshals the EventType to text.

func (EventType) String

func (e EventType) String() string

String returns a string representation of the EventType.

func (*EventType) UnmarshalJSON

func (e *EventType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the EventType from JSON.

func (*EventType) UnmarshalText

func (e *EventType) UnmarshalText(data []byte) error

UnmarshalText unmarshals the EventType from text.

type Runner

type Runner interface {
	// Run the commands.
	//
	// Return error if there was an initialization error, or any of
	// the running commands returned with a non-zero exit code.
	Run(cmds []Cmd) error
}

Runner runs the commands.

func NewRunner

func NewRunner(options ...RunnerOption) Runner

NewRunner returns a new Runner.

type RunnerOption

type RunnerOption func(*runner)

RunnerOption is an option for a new Runner.

func WithClock

func WithClock(clock func() time.Time) RunnerOption

WithClock returns a RunnerOption that will make the Runner use the given Clock.

func WithEventHandler

func WithEventHandler(eventHandler func(*Event)) RunnerOption

WithEventHandler returns a RunnerOption that will use the given EventHandler.

func WithFastFail

func WithFastFail() RunnerOption

WithFastFail returns a RunnerOption that will return error fun Run as soon as one of the commands fails.

func WithMaxConcurrentCmds

func WithMaxConcurrentCmds(maxConcurrentCmds int) RunnerOption

WithMaxConcurrentCmds returns a RunnerOption that will make the Runner only run maxConcurrentCmds at once, or unlimited if 0.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier