Documentation ¶
Index ¶
- Variables
- func SetSysProcAttribute(cmd *exec.Cmd)
- type Context
- type Error
- type FinishedFunc
- type IDType
- type Manager
- func (pm *Manager) Add(parentPID IDType, description string, cancel context.CancelFunc) (IDType, FinishedFunc)
- func (pm *Manager) AddContext(parent context.Context, description string) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc)
- func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finshed FinishedFunc)
- func (pm *Manager) Cancel(pid IDType)
- func (pm *Manager) Exec(desc, cmdName string, args ...string) (string, string, error)
- func (pm *Manager) ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error)
- func (pm *Manager) ExecDirEnv(timeout time.Duration, dir, desc string, env []string, cmdName string, ...) (string, string, error)
- func (pm *Manager) ExecDirEnvStdIn(timeout time.Duration, dir, desc string, env []string, stdIn io.Reader, ...) (string, string, error)
- func (pm *Manager) ExecTimeout(timeout time.Duration, desc, cmdName string, args ...string) (string, string, error)
- func (pm *Manager) Processes(onlyRoots bool) []*Process
- func (pm *Manager) Remove(pid IDType)
- type Process
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultContext is the default context to run processing commands in DefaultContext = context.Background() )
var ProcessContextKey interface{} = "process-context"
ProcessContextKey is the key under which process contexts are stored
Functions ¶
func SetSysProcAttribute ¶ added in v1.16.9
SetSysProcAttribute sets the common SysProcAttrs for commands
Types ¶
type Context ¶ added in v1.16.0
Context is a wrapper around context.Context and contains the current pid for this context
func GetContext ¶ added in v1.16.0
GetContext will return a process context if one exists
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
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 GetParentPID ¶ added in v1.16.0
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) 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.
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
AddChild adds a child process Note: this function will behave nicely even if p is nil
func (*Process) Children ¶ added in v1.16.0
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
RemoveChild removes a child process Note: this function will behave nicely even if p is nil