process

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INVALID_HANDLE int = 0

	CTRL_C_SIGNAL     int = 0
	CTRL_BREAK_SIGNAL int = 1
	KILL_SIGNAL       int = 2

	// bit mask
	SEND_NO_SIGNAL         int = 0
	SEND_CTRL_C_SIGNAL     int = 1
	SEND_CTRL_BREAK_SIGNAL int = 2
	SEND_KILL_SIGNAL       int = 4
)

Variables

View Source
var ChildMarker string = strconv.Itoa(os.Getpid()) + "_" + strconv.FormatInt(time.Now().Unix(), 16)

pid_numSecondsSinceEpoch

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

ErrCancelled means command being cancelled

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

ErrTimeout means command timeout

View Source
var Log *logging.Logger

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 Procd string
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 decides whether print extra information

Functions

func Run

func Run(opts *Options, cancel chan struct{}, chCmdStr chan string) (chan *Command, chan string, chan int, 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, 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 ChildCheckRecord added in v0.4.0

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

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

	Executed chan int // for checking if the command has been executed
	// 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) Run

func (c *Command) Run(opts *Options, tryNumber int) (chan string, error)

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

func (*Command) String

func (c *Command) String() string

type ImmediateLineWriter added in v0.4.0

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

ImmediateLineWriter is safe to use concurrently

func NewImmediateLineWriter added in v0.4.0

func NewImmediateLineWriter(lock *sync.Mutex, numJobs int, cmdId uint64, tryNumber int) *ImmediateLineWriter

func (*ImmediateLineWriter) WritePrefixedLines added in v0.4.0

func (lw *ImmediateLineWriter) WritePrefixedLines(input string, outfh *os.File)

type ImmediateWriter added in v0.4.0

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

func NewImmediateWriter added in v0.4.0

func NewImmediateWriter(lineWriter *ImmediateLineWriter, fh *os.File) *ImmediateWriter

func (ImmediateWriter) Write added in v0.4.0

func (iw ImmediateWriter) Write(p []byte) (n int, err error)

type IntSet added in v0.4.0

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

from https://softwareengineering.stackexchange.com/questions/177428/sets-data-structure-in-golang

func (*IntSet) Add added in v0.4.0

func (set *IntSet) Add(i int) bool

type Options

type Options struct {
	DryRun bool // just print command
	Jobs   int  // max jobs number

	ETA    bool // show eta
	ETABar *pb.ProgressBar

	KeepOrder           bool          // keep output order
	Retries             int           // max retry chances
	RetryInterval       time.Duration // retry interval
	OutFileHandle       *os.File      // where to send stdout
	ErrFileHandle       *os.File      // where to send stderr
	ImmediateOutput     bool          // print output immediately and interleaved
	ImmediateLock       sync.Mutex    // make immediate output thread-safe and do one write at a time
	PrintRetryOutput    bool          // print output from retries
	Timeout             time.Duration // timeout
	StopOnErr           bool          // stop on any error
	NoStopExes          []string      // exe names to exclude from stop signal
	NoKillExes          []string      // exe names to exclude from kill signal
	CleanupTime         time.Duration // time to allow children to clean up
	PropExitStatus      bool          // propagate child exit status
	RecordSuccessfulCmd bool          // send successful command to channel
	Verbose             bool
}

Options contains the options

type ProcessRecord added in v0.4.0

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

type TopLevelEnum added in v0.4.0

type TopLevelEnum int
const (
	NotTopLevel TopLevelEnum = 0
	TopLevel    TopLevelEnum = 1
)

Jump to

Keyboard shortcuts

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