Documentation
¶
Overview ¶
Package acpexec spawns a subprocess and wires its stdin/stdout together as a single io.ReadWriteCloser, the transport shape libacp's connections expect.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockedBuffer ¶
type LockedBuffer struct {
// contains filtered or unexported fields
}
LockedBuffer is a concurrency-safe io.Writer around a bytes.Buffer, for use with WithStderr when a caller's String() read races the subprocess reader goroutine's writes.
func (*LockedBuffer) String ¶
func (b *LockedBuffer) String() string
String returns everything written so far.
type Option ¶
type Option func(*config)
Option configures Spawn. See WithStderr and WithKillGrace.
func WithKillGrace ¶
WithKillGrace overrides how long Close waits for the subprocess to exit on its own (after closing its stdin) before it escalates to Process.Kill; the default is 5 seconds.
func WithStderr ¶
WithStderr forwards the subprocess's stderr to w as it's written, instead of the default (io.Discard); use a *LockedBuffer if the caller reads w's contents from a different goroutine than the one writing it.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process is a spawned subprocess wired up as an io.ReadWriteCloser: Read pulls from its stdout, Write pushes to its stdin, Close begins shutdown.
func Spawn ¶
Spawn starts cmd (claiming its Stdin/Stdout via exec.Cmd.StdinPipe/StdoutPipe, which callers must not set already) and returns it as a Process, tearing it down exactly as Close would if ctx is cancelled before the subprocess exits.
type Supervisor ¶
type Supervisor struct {
// Command builds a fresh *exec.Cmd for each (re)start; required, since an
// exec.Cmd cannot be reused once started.
Command func(ctx context.Context) *exec.Cmd
// MaxRestarts caps how many times Serve respawns after the first attempt;
// zero means one attempt with no restarts.
MaxRestarts int
// Backoff returns the delay before restart attempt n (1-based, nil means
// no delay); Serve honors ctx cancellation while waiting.
Backoff func(attempt int) time.Duration
// OnRestart, if set, is called just before each genuine restart with the
// 1-based restart number and the triggering error, but not for a startup
// or non-retryable error (check libacp.IsStartupError).
OnRestart func(attempt int, cause error)
// SpawnOptions are forwarded to Spawn on every attempt (e.g. WithStderr).
SpawnOptions []Option
}
Supervisor keeps an agent subprocess alive across transient crashes by respawning it with backoff and re-running a caller-supplied session. A startup error (IsStartupError) is never retried.
func (*Supervisor) Serve ¶
func (s *Supervisor) Serve(ctx context.Context, session func(ctx context.Context, proc *Process, attempt int) error) error
Serve spawns the agent and runs session against each live Process, passing a zero-based attempt counter, until session succeeds, ctx is cancelled, or a failure that is not worth retrying (per libacp.IsRetryableError, up to MaxRestarts) occurs.