process

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2017 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const UnknownExit = 1

UnknownExit is used when the return/exit-code of the command is not known.

Variables

View Source
var BufferSize = 1048576

BufferSize determines how much output will be read into memory before resorting to using a temporary file

View Source
var WaitingMultiplier = 4

WaitingMultiplier determines how many finished processes can be waiting before Runner blocks waiting for the slowest process finishes. Increasing this improves concurrency at the expense of memory.

Functions

func Cleanup added in v0.3.6

func Cleanup()

Cleanup is a best-effort to remove all temporary files created by process. Users can call it manually to remove them.

func Runner

func Runner(commands <-chan string, cancel <-chan bool, opts *Options) chan *Command

Runner accepts commands from a channel and sends a bufio.Reader on the returned channel. done allows the caller to stop Runner, for example if an error occurs. It will parallelize according to GOMAXPROCS. See Options for more details.

Types

type CallBack added in v0.3.6

type CallBack func(io.Reader, io.WriteCloser) error

CallBack is an optional function the user can provide to process the stdout stream of the called Command. The user is responsible for closing the io.Writer

type Command

type Command struct {
	*bufio.Reader

	Err      error
	CmdStr   string
	Duration time.Duration
	// contains filtered or unexported fields
}

Command contains a buffered reader with the realized stdout of the process along with the exit code.

func Run

func Run(command string, opts *Options, env ...string) *Command

Run takes a command string, executes the command, Blocks until the output is finished and returns a *Command that is an io.Reader. See Options for additional details.

func (*Command) Cleanup added in v0.3.5

func (c *Command) Cleanup()

Cleanup makes sure the tempfile is closed an deleted.

func (*Command) Close added in v0.3.5

func (c *Command) Close() error

Close the temp file associated with the command

func (*Command) ExitCode

func (c *Command) ExitCode() int

ExitCode returns the exit code associated with a given error

func (*Command) String

func (c *Command) String() string

String returns a representation of the command that includes run-time, error (if any) and the first 20 chars of stdout.

type Options added in v0.3.6

type Options struct {
	// A callback to be applied to the output of the command. The user is responsible
	// for closing the io.Writer insde the this function.
	CallBack CallBack
	// Ordered keeps the output in order even when the processes finish in a different order.io
	// This can come at the expense of performance when waiting on a long process.
	Ordered bool
	// Retries indicates the number of times a process will be retried if it has
	// a non-zero exit code.
	Retries int
}

Options holds the options to send to Runner.

Jump to

Keyboard shortcuts

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