subproc

package
v0.137.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package subproc provides bounded-duration subprocess execution for short-lived read-only commands (git status, docker ps). Each call emits a warning to stderr after warnAfter and is cancelled at timeout.

Index

Constants

View Source
const (
	DefaultWarnAfter = 3 * time.Second
	DefaultTimeout   = 10 * time.Second
)

Default thresholds for RunWithWarnAndTimeout.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

type Runner interface {
	// RunWithWarnAndTimeout runs `name args...` bounded by the configured
	// warnAfter/timeout. On timeout it returns a non-nil error and the
	// caller should treat the operation as skipped.
	//
	// op is a human-readable operation label used in warn/skip messages
	// (e.g. "git status --porcelain").
	RunWithWarnAndTimeout(
		ctx context.Context,
		op string,
		name string,
		args ...string,
	) ([]byte, error)

	// RunWithWarnAndTimeoutDir is identical to RunWithWarnAndTimeout but sets
	// cmd.Dir = dir before running, preserving the working directory.
	RunWithWarnAndTimeoutDir(
		ctx context.Context,
		op string,
		dir string,
		name string,
		args ...string,
	) ([]byte, error)
}

Runner runs short subprocesses with warn + timeout semantics.

func NewRunner

func NewRunner() Runner

NewRunner returns a Runner using the default 3s/10s thresholds.

func NewRunnerWithThresholds

func NewRunnerWithThresholds(warnAfter, timeout time.Duration) Runner

NewRunnerWithThresholds returns a Runner with custom thresholds (for tests).

Jump to

Keyboard shortcuts

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