exec

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPathNotSet indicates a Cmd object which doesn't have a path value
	ErrPathNotSet = fmt.Errorf("cmd: no path specified")

	// ErrArgsRequiresPathAsFirstArg indicates a Cmd object which doesn't have
	// args[0] == path
	ErrArgsRequiresPathAsFirstArg = fmt.Errorf("cmd: args[0] un-equal to path")
)

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Path      string
	Args      []string
	OutputDir string
	Env       EnvMap
}

Cmd represents an executable command NB(prateek): golang's os/exec package makes an implicit requirement that Args[0] to be set to Path, iff Args is set at all. This package follows the convention but makes that requirement explicit. ProcessMonitor reports error when being constructed.

func (Cmd) Validate

func (c Cmd) Validate() error

Validate ensures the provide Cmd object conforms to the expected structure.

type EnvMap

type EnvMap map[string]string

EnvMap is a map of Key-Value pairs representing the environment variables. NB(prateek): these are a set of 'delta' vars, i.e. they are appended to the vars already present in `os.Environ()`.

type ProcessListener

type ProcessListener interface {
	// OnComplete is executed in the event of process termination without error
	OnComplete()

	// OnError is executed in the event of process termination with error
	OnError(error)
}

ProcessListener permits users of the API to be notified of process termination

func NewProcessListener

func NewProcessListener(
	completeFn func(),
	errFn func(error),
) ProcessListener

NewProcessListener returns a new ProcessListener

type ProcessMonitor

type ProcessMonitor interface {
	// Start starts the provided process
	Start() error

	// Stop stops any running process
	// NB(prateek): the golang runtime reports error inconsistently upon calling
	// `process.Kill()`. Consequently, it is not guaranteed which notification method
	// of the ProcessListener (OnComplete/OnError) is invoked upon process termination.
	// Refer https://github.com/golang/go/blob/master/src/os/exec_plan9.go#L51-L63
	Stop() error

	// Running returns a flag indicating if the process is running
	Running() bool

	// Err returns any error encountered
	Err() error

	// Close releases any held resources
	Close() error

	// StdoutPath returns the path to the process stdout file
	StdoutPath() string

	// StderrPath returns the path to the process stderr file
	StderrPath() string
}

ProcessMonitor provides necessary controls to supervise a process

func NewProcessMonitor

func NewProcessMonitor(cmd Cmd, pl ProcessListener) (ProcessMonitor, error)

NewProcessMonitor creates a new ProcessMonitor

Directories

Path Synopsis
Package exec is a generated GoMock package.
Package exec is a generated GoMock package.

Jump to

Keyboard shortcuts

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