Documentation
¶
Index ¶
- type Manager
- func (m *Manager) Get(id string) *Process
- func (m *Manager) IDs() []string
- func (m *Manager) Restart(id string) error
- func (m *Manager) Snapshot() []*Process
- func (m *Manager) Start(id string) error
- func (m *Manager) StartAll() error
- func (m *Manager) Stop(id string) error
- func (m *Manager) StopAll()
- func (m *Manager) SwitchWorktree(newRoot string) error
- type OutputFunc
- type OutputLine
- type Process
- func (p *Process) ClearOutput()
- func (p *Process) Cwd() string
- func (p *Process) Restart(graceTimeout time.Duration) error
- func (p *Process) RestartCount() int
- func (p *Process) SetCwd(cwd string)
- func (p *Process) Start() error
- func (p *Process) State() State
- func (p *Process) Stop(graceTimeout time.Duration) error
- type RingBuffer
- type State
- type StateChangeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns and coordinates all managed processes. It is the single point of truth for process lifecycle across the application.
func NewManager ¶
func NewManager(cfg *config.Config, onState StateChangeFunc, onOutput OutputFunc) *Manager
NewManager constructs a Manager from the parsed config.
- cfg the fully-parsed lazyproc config
- onState called whenever any process changes state (may be nil)
- onOutput called for every output line from any process (may be nil)
func (*Manager) Snapshot ¶
Snapshot returns a point-in-time slice of all processes. The returned slice is safe to iterate without holding the manager lock, though individual Process state fields have their own locks.
func (*Manager) Start ¶
Start starts a single process by id. Returns an error if the id is unknown or the process fails to start.
func (*Manager) StartAll ¶
StartAll starts every process that is currently stopped or crashed. Processes with dependencies are started after their dependencies reach the required state (Ready, or Running when no ready_when is configured). This call blocks until the full startup sequence completes or an error occurs.
func (*Manager) StopAll ¶
func (m *Manager) StopAll()
StopAll sends SIGTERM to every running process group concurrently, then waits for all of them (SIGKILL after the grace period for survivors).
func (*Manager) SwitchWorktree ¶
SwitchWorktree stops all processes, updates every process's working directory to the new worktree root, clears their output buffers, then restarts only the processes that were actively running or ready before the switch (i.e. the ones the user had started). Processes that were stopped or crashed are left stopped so the user's explicit stop choices are preserved.
If a process has a relative cwd defined in its config, it is re-joined against the new worktree root so it still resolves correctly in the new tree.
type OutputFunc ¶
type OutputFunc func(id string, line OutputLine)
OutputFunc is called for each line captured from stdout/stderr. Implementations must be non-blocking.
type OutputLine ¶
OutputLine is a single captured line from a process pipe.
type Process ¶
type Process struct {
// Immutable identity & config set at construction time.
ID string
// Ring buffer holding captured output lines.
Output *RingBuffer
// contains filtered or unexported fields
}
Process represents a single managed child process.
func NewProcess ¶
func NewProcess( id string, cfg config.Process, shell string, logCap int, onState StateChangeFunc, onOutput OutputFunc, ) *Process
NewProcess constructs a Process from a config entry.
- id unique name from the config map key
- cfg per-process config block
- shell shell binary (from global settings, e.g. "/bin/sh")
- logCap ring buffer size (from global settings)
- onState state-change callback (may be nil)
- onOutput per-line output callback (may be nil)
func (*Process) ClearOutput ¶
func (p *Process) ClearOutput()
ClearOutput empties the output ring buffer.
func (*Process) Cwd ¶
Cwd returns the current working directory configured for this process (thread-safe).
func (*Process) RestartCount ¶
RestartCount returns how many times the process has been restarted.
func (*Process) SetCwd ¶
SetCwd updates the working directory used for future Start calls. It has no effect on a currently running process.
func (*Process) Start ¶
Start spawns the process. It is safe to call from any goroutine. Returns an error if the process is already running or cannot be started.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a circular line buffer When the byte capacity is exhausted, oldest bytes are discarded to make room. All methods are safe for concurrent use.
func NewRingBuffer ¶
func NewRingBuffer(maxLines int) *RingBuffer
func (*RingBuffer) Cap ¶
func (r *RingBuffer) Cap() int
func (*RingBuffer) Clear ¶
func (r *RingBuffer) Clear()
func (*RingBuffer) Len ¶
func (r *RingBuffer) Len() int
func (*RingBuffer) Lines ¶
func (r *RingBuffer) Lines() []string
func (*RingBuffer) Push ¶
func (r *RingBuffer) Push(line string)
type State ¶
type State int
State represents the lifecycle state of a managed process.
const ( StateStopped State = iota // not yet started or explicitly stopped StateStarting // cmd.Start() called, waiting for readiness StateRunning // running, no ready_when defined (or pattern not yet matched) StateReady // ready_when pattern matched StateCrashed // exited with non-zero status or unexpected exit StateRestarting // being restarted after a crash )
type StateChangeFunc ¶
StateChangeFunc is called whenever a process transitions to a new state. Implementations must be non-blocking (e.g. send on a buffered channel).