process

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = fmt.Errorf("cancelled")

ErrCancelled means command being cancelled

View Source
var ErrTimeout = fmt.Errorf("time out")

ErrTimeout means command timeout

Log is *logging.Logger

View Source
var OutputChunkSize = 16384 // 16K

OutputChunkSize is buffer size of output string chunk sent to channel, default 16K.

View Source
var TmpOutputDataBuffer = 1048576 // 1M

TmpOutputDataBuffer is buffer size for output of a command before saving to tmpfile, default 1M.

View Source
var Verbose bool

Verbose decide whether print extra information

Functions

func Run

func Run(opts *Options, cancel chan struct{}, chCmdStr chan string) (chan *Command, chan string, chan int)

Run runs commands in parallel from channel chCmdStr, and returns a Command channel, and a done channel to ensure safe exit.

func Run4Output

func Run4Output(opts *Options, cancel chan struct{}, chCmdStr chan string) (chan string, chan string, chan int)

Run4Output runs commands in parallel from channel chCmdStr, and returns an output text channel, and a done channel to ensure safe exit.

Types

type Command

type Command struct {
	ID  uint64 // ID
	Cmd string // command

	Cancel  chan struct{} // channel for close
	Timeout time.Duration // time out

	Ch chan string // channel for stdout

	Err      error         // Error
	Duration time.Duration // runtime
	// contains filtered or unexported fields
}

Command is the Command struct

func NewCommand

func NewCommand(id uint64, cmdStr string, cancel chan struct{}, timeout time.Duration) *Command

NewCommand create a Command

func (*Command) Cleanup

func (c *Command) Cleanup() error

Cleanup removes tmpfile

func (*Command) ExitCode

func (c *Command) ExitCode() int

ExitCode returns the exit code associated with a given error

func (*Command) Run

func (c *Command) Run() error

Run runs a command and send output to command.Ch in background.

func (*Command) String

func (c *Command) String() string

type Options

type Options struct {
	DryRun              bool          // just print command
	Jobs                int           // max jobs number
	KeepOrder           bool          // keep output order
	Retries             int           // max retry chances
	RetryInterval       time.Duration // retry interval
	Timeout             time.Duration // timeout
	StopOnErr           bool          // stop on any error
	RecordSuccessfulCmd bool          // send successful command to channel
	Verbose             bool
}

Options contains the options

Jump to

Keyboard shortcuts

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