Documentation
¶
Overview ¶
Package extcmd supports use cases in which a command is supposed be started non-blocking as a result of an incoming HTTP requests, e.g., ActionKit's start call. It allows retrieval of log messages for streaming to the agent as well as stopping and status access.
This package maintains state through a global variable that is a mapping from a random ID to CmdState. The random ID is contained within CmdState.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveCmdState ¶
func RemoveCmdState(id string)
RemoveCmdState removes the state with the given ID. A no-op in case there is no state with this ID. It is the caller's responsibility to ensure that the exec.Cmd itself is stopped.
Types ¶
type CmdState ¶
func GetCmdState ¶
GetCmdState returns the state stored under the given ID or an error in case there is no persisted state under the ID.
func NewCmdState ¶
NewCmdState create a new CmdState and registers it as a global state. The expected call pattern is that NewCmdState is called immediately after the exec.Cmd is created, but before the Cmd is started.
func (*CmdState) ExitCode ¶ added in v1.10.6
ExitCode returns the command's exit code, or -1 while it is still running or if it was terminated by a signal, matching os.ProcessState.ExitCode(). It is safe to call concurrently with the Wait goroutine.
func (*CmdState) GetMessages ¶
func (*CmdState) Wait ¶ added in v1.10.6
Wait blocks until the command exits and records its exit code. It must be called exactly once — typically as `go cmdState.Wait()` right after the command is started. Wait is the sole reader of Cmd.ProcessState, so concurrent callers must obtain the exit code via ExitCode rather than reading Cmd.ProcessState directly; doing the latter races this method. The error returned by exec.Cmd.Wait is passed through for logging.