process

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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) Get

func (m *Manager) Get(id string) *Process

Get returns the Process with the given id, or nil if it does not exist.

func (*Manager) IDs

func (m *Manager) IDs() []string

IDs returns all known process IDs in an unspecified order.

func (*Manager) Restart

func (m *Manager) Restart(id string) error

Restart restarts a single process by id.

func (*Manager) Snapshot

func (m *Manager) Snapshot() []*Process

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

func (m *Manager) Start(id string) error

Start starts a single process by id. Returns an error if the id is unknown or the process fails to start.

func (*Manager) StartAll

func (m *Manager) StartAll() error

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) Stop

func (m *Manager) Stop(id string) error

Stop stops a single process by id using the default grace timeout.

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

func (m *Manager) SwitchWorktree(newRoot string) error

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

type OutputLine struct {
	Text      string
	Timestamp time.Time
}

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

func (p *Process) Cwd() string

Cwd returns the current working directory configured for this process (thread-safe).

func (*Process) Restart

func (p *Process) Restart(graceTimeout time.Duration) error

Restart stops the process (if running) and starts it again.

func (*Process) RestartCount

func (p *Process) RestartCount() int

RestartCount returns how many times the process has been restarted.

func (*Process) SetCwd

func (p *Process) SetCwd(cwd string)

SetCwd updates the working directory used for future Start calls. It has no effect on a currently running process.

func (*Process) Start

func (p *Process) Start() error

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.

func (*Process) State

func (p *Process) State() State

State returns the current process state (thread-safe).

func (*Process) Stop

func (p *Process) Stop(graceTimeout time.Duration) error

Stop sends SIGTERM to the process group, waits up to graceTimeout, then sends SIGKILL to any survivors.

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
)

func (State) String

func (s State) String() string

String returns a human-readable label for the state.

type StateChangeFunc

type StateChangeFunc func(id string, state State)

StateChangeFunc is called whenever a process transitions to a new state. Implementations must be non-blocking (e.g. send on a buffered channel).

Jump to

Keyboard shortcuts

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