process

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 9 Imported by: 165

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultContext is the default context to run processing commands in
	DefaultContext = context.Background()
)
View Source
var ProcessContextKey interface{} = "process-context"

ProcessContextKey is the key under which process contexts are stored

Functions

This section is empty.

Types

type Context added in v1.16.0

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context is a wrapper around context.Context and contains the current pid for this context

func GetContext added in v1.16.0

func GetContext(ctx context.Context) *Context

GetContext will return a process context if one exists

func (*Context) GetPID added in v1.16.0

func (c *Context) GetPID() IDType

GetPID returns the PID for this context

func (*Context) GetParent added in v1.16.0

func (c *Context) GetParent() *Context

GetParent returns the parent process context (if any)

func (*Context) Value added in v1.16.0

func (c *Context) Value(key interface{}) interface{}

Value is part of the interface for context.Context. We mostly defer to the internal context - but we return this in response to the ProcessContextKey

type Error added in v1.13.0

type Error struct {
	PID         IDType
	Description string
	Err         error
	CtxErr      error
	Stdout      string
	Stderr      string
}

Error is a wrapped error describing the error results of Process Execution

func (*Error) Error added in v1.13.0

func (err *Error) Error() string

func (*Error) Unwrap added in v1.13.0

func (err *Error) Unwrap() error

Unwrap implements the unwrappable implicit interface for go1.13 Unwrap()

type FinishedFunc added in v1.16.0

type FinishedFunc = context.CancelFunc

FinishedFunc is a function that marks that the process is finished and can be removed from the process table - it is simply an alias for context.CancelFunc and is only for documentary purposes

type IDType added in v1.16.0

type IDType string

IDType is a pid type

func GetPID added in v1.16.0

func GetPID(ctx context.Context) IDType

GetPID returns the PID for this context

func GetParentPID added in v1.16.0

func GetParentPID(ctx context.Context) IDType

GetParentPID returns the ParentPID for this context

type Manager added in v1.1.0

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

Manager manages all processes and counts PIDs.

func GetManager added in v1.1.0

func GetManager() *Manager

GetManager returns a Manager and initializes one as singleton if there's none yet

func (*Manager) Add added in v1.1.0

func (pm *Manager) Add(parentPID IDType, description string, cancel context.CancelFunc) (IDType, FinishedFunc)

Add create a new process

func (*Manager) AddContext added in v1.16.0

func (pm *Manager) AddContext(parent context.Context, description string) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc)

AddContext creates a new context and adds it as a process. Once the process is finished, finished must be called to remove the process from the process table. It should not be called until the process is finished but must always be called.

cancel should be used to cancel the returned context, however it will not remove the process from the process table. finished will cancel the returned context and remove it from the process table.

Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the process table.

func (*Manager) AddContextTimeout added in v1.16.0

func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finshed FinishedFunc)

AddContextTimeout creates a new context and add it as a process. Once the process is finished, finished must be called to remove the process from the process table. It should not be called until the process is finished but must always be called.

cancel should be used to cancel the returned context, however it will not remove the process from the process table. finished will cancel the returned context and remove it from the process table.

Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the process table.

func (*Manager) Cancel added in v1.11.0

func (pm *Manager) Cancel(pid IDType)

Cancel a process in the ProcessManager.

func (*Manager) Exec added in v1.1.0

func (pm *Manager) Exec(desc, cmdName string, args ...string) (string, string, error)

Exec a command and use the default timeout.

func (*Manager) ExecDir added in v1.1.0

func (pm *Manager) ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error)

ExecDir a command and use the default timeout.

func (*Manager) ExecDirEnv added in v1.1.0

func (pm *Manager) ExecDirEnv(timeout time.Duration, dir, desc string, env []string, cmdName string, args ...string) (string, string, error)

ExecDirEnv runs a command in given path and environment variables, and waits for its completion up to the given timeout (or DefaultTimeout if -1 is given). Returns its complete stdout and stderr outputs and an error, if any (including timeout)

func (*Manager) ExecDirEnvStdIn added in v1.9.5

func (pm *Manager) ExecDirEnvStdIn(timeout time.Duration, dir, desc string, env []string, stdIn io.Reader, cmdName string, args ...string) (string, string, error)

ExecDirEnvStdIn runs a command in given path and environment variables with provided stdIN, and waits for its completion up to the given timeout (or DefaultTimeout if -1 is given). Returns its complete stdout and stderr outputs and an error, if any (including timeout)

func (*Manager) ExecTimeout added in v1.1.0

func (pm *Manager) ExecTimeout(timeout time.Duration, desc, cmdName string, args ...string) (string, string, error)

ExecTimeout a command and use a specific timeout duration.

func (*Manager) Processes added in v1.1.0

func (pm *Manager) Processes(onlyRoots bool) []*Process

Processes gets the processes in a thread safe manner

func (*Manager) Remove added in v1.1.0

func (pm *Manager) Remove(pid IDType)

Remove a process from the ProcessManager.

type Process

type Process struct {
	PID         IDType // Process ID, not system one.
	ParentPID   IDType
	Description string
	Start       time.Time
	Cancel      context.CancelFunc
	// contains filtered or unexported fields
}

Process represents a working process inheriting from Gitea.

func (*Process) AddChild added in v1.16.0

func (p *Process) AddChild(child *Process)

AddChild adds a child process Note: this function will behave nicely even if p is nil

func (*Process) Children added in v1.16.0

func (p *Process) Children() (children []*Process)

Children gets the children of the process Note: this function will behave nicely even if p is nil

func (*Process) RemoveChild added in v1.16.0

func (p *Process) RemoveChild(process *Process)

RemoveChild removes a child process Note: this function will behave nicely even if p is nil

Jump to

Keyboard shortcuts

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