Documentation
¶
Overview ¶
Package process provides subprocess execution with context cancellation, signal handling, and structured output capture.
Index ¶
- type Command
- type Result
- type Runner
- type SubprocessProvider
- func (p *SubprocessProvider[I, O]) Execute(ctx context.Context, input I) (O, error)
- func (p *SubprocessProvider[I, O]) IsAvailable(ctx context.Context) bool
- func (p *SubprocessProvider[I, O]) Name() string
- func (p *SubprocessProvider[I, O]) WithAvailabilityCheck(fn func(context.Context) bool) *SubprocessProvider[I, O]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Binary is the executable path or name (resolved via PATH).
Binary string
// Args are the command-line arguments.
Args []string
// Dir is the working directory. If empty, uses the current directory.
Dir string
// Env is additional environment variables (key=value). Merged with os.Environ.
Env []string
// Stdin provides input to the process. May be nil.
Stdin io.Reader
// GracePeriod is how long to wait after SIGTERM before SIGKILL.
// Defaults to 5 seconds if zero.
GracePeriod time.Duration
}
Command configures a subprocess to execute.
type Result ¶
type Result struct {
// Stdout is the captured standard output.
Stdout []byte
// Stderr is the captured standard error.
Stderr []byte
// ExitCode is the process exit code. -1 if the process was killed.
ExitCode int
// Duration is how long the process ran.
Duration time.Duration
}
Result holds the output and status of a completed subprocess.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner wraps subprocess execution with persistent resilience state. Use NewRunner to create one, then call Run repeatedly. The circuit breaker state persists across calls — repeated crashes trip the breaker.
func NewRunner ¶
func NewRunner(cfg provider.ResilienceConfig) *Runner
NewRunner creates a Runner with the given resilience config. Nil config fields are skipped. Empty config means Run() calls process.Run directly.
type SubprocessProvider ¶
type SubprocessProvider[I, O any] struct { // contains filtered or unexported fields }
SubprocessProvider wraps a Command as a provider.RequestResponse. The input function builds a Command from the input, and the output function parses the Result into the desired output type.
func NewSubprocessProvider ¶
func NewSubprocessProvider[I, O any]( name string, buildCmd func(I) Command, parseOut func(*Result) (O, error), ) *SubprocessProvider[I, O]
NewSubprocessProvider creates a RequestResponse provider backed by subprocess execution.
func (*SubprocessProvider[I, O]) Execute ¶
func (p *SubprocessProvider[I, O]) Execute(ctx context.Context, input I) (O, error)
func (*SubprocessProvider[I, O]) IsAvailable ¶
func (p *SubprocessProvider[I, O]) IsAvailable(ctx context.Context) bool
func (*SubprocessProvider[I, O]) Name ¶
func (p *SubprocessProvider[I, O]) Name() string
func (*SubprocessProvider[I, O]) WithAvailabilityCheck ¶
func (p *SubprocessProvider[I, O]) WithAvailabilityCheck(fn func(context.Context) bool) *SubprocessProvider[I, O]
WithAvailabilityCheck sets a custom availability check for the provider.