execx

package
v0.5.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package execx runs external processes with a hard timeout and reliable process-tree termination. A hung `go build`, `npm install`, or `git` can no longer wedge a Krate build: the deadline is enforced and the whole tree is killed (on Windows `npx`/`go` are shims that spawn children, so killing only the direct child would leak the real work and block on its pipes).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(ctx context.Context, name string, args ...string) *exec.Cmd

Command builds an *exec.Cmd wired for tree termination: it is configured to start a new process group (Unix), and Cancel kills the whole tree.

func ConfigureTree

func ConfigureTree(cmd *exec.Cmd)

ConfigureTree prepares a manually-built *exec.Cmd (e.g. a long-lived sidecar started with Start rather than Command) so KillTree can terminate its whole process group on Unix.

func DefaultTimeout

func DefaultTimeout() time.Duration

DefaultTimeout returns the process-wide default timeout from the KRATE_EXEC_TIMEOUT environment variable (a Go duration, e.g. "90s"), or 0 when unset/invalid (0 means "no default" - callers may still pass an explicit timeout).

func KillTree

func KillTree(cmd *exec.Cmd)

KillTree terminates cmd and all of its child processes.

func Output

func Output(ctx context.Context, timeout time.Duration, dir string, env []string, name string, args ...string) ([]byte, error)

Output is Run for the common case of needing only stdout.

func Run

func Run(ctx context.Context, timeout time.Duration, dir string, env []string, name string, args ...string) (stdout, stderr []byte, err error)

Run executes name/args, enforcing timeout (falling back to DefaultTimeout when timeout <= 0). dir is the working directory (empty = inherit); env entries are appended to the current environment. It returns stdout, stderr, and an error that is descriptive on timeout.

func Timeout

func Timeout(envVar string, def time.Duration) time.Duration

Timeout resolves an operation-specific timeout from envVar. Unset -> def; "0"/"off"/"none" -> 0 (disabled); a valid Go duration -> that value. This lets a slow machine raise one operation's budget without loosening the others.

Types

This section is empty.

Jump to

Keyboard shortcuts

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