background

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureChildProcessGroup

func ConfigureChildProcessGroup(cmd *exec.Cmd)

ConfigureChildProcessGroup puts a child into its own process group so the whole group can be signalled as a unit. terminateProcess depends on this: it signals the negative PID (the group), so any process the child forks dies with it instead of being orphaned. Must be called before cmd.Start.

func DefaultRoot

func DefaultRoot(env map[string]string) string

func TerminateProcess

func TerminateProcess(pid int) error

TerminateProcess stops a background process by PID — on Windows its process tree; on POSIX its whole process group when the PID leads its own group (the invariant ConfigureChildProcessGroup establishes for processes started through this package), otherwise just the individual PID. The PID-only fallback is deliberate — signalling a non-leader's group could hit unrelated processes — but it means descendants of a non-leader are NOT reaped; pass a group leader to guarantee group termination. Exported for callers that hold a raw PID and cannot route through the manager, e.g. cleaning up a just-launched child whose PID could not be recorded.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(rootDir string) (*Manager, error)

func NewManagerWithOptions

func NewManagerWithOptions(options ManagerOptions) (*Manager, error)

func (*Manager) Get

func (manager *Manager) Get(taskID string) (Task, bool)

func (*Manager) Kill

func (manager *Manager) Kill(taskID string) error

func (*Manager) KillRunning

func (manager *Manager) KillRunning() error

func (*Manager) List

func (manager *Manager) List() []Task

func (*Manager) ListByParent

func (manager *Manager) ListByParent(parentID string) []Task

func (*Manager) LoadWarnings

func (manager *Manager) LoadWarnings() []string

func (*Manager) MarkExited

func (manager *Manager) MarkExited(taskID string, status Status, exitCode int) error

func (*Manager) OutputPath

func (manager *Manager) OutputPath(taskID string) string

func (*Manager) Register

func (manager *Manager) Register(input RegisterInput) (string, error)

func (*Manager) RootDir

func (manager *Manager) RootDir() string

func (*Manager) SetPID

func (manager *Manager) SetPID(taskID string, pid int) error

func (*Manager) UpdateStatus

func (manager *Manager) UpdateStatus(taskID string, status Status, exitCode int) error

type ManagerOptions

type ManagerOptions struct {
	RootDir     string
	Env         map[string]string
	Now         func() time.Time
	KillProcess func(pid int) error
}

type RegisterInput

type RegisterInput struct {
	TaskID         string
	Type           string
	SpecialistName string
	Description    string
	ParentID       string
	PID            int
	OutputFile     string
}

type Status

type Status string
const (
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusError     Status = "error"
	StatusKilled    Status = "killed"
)

type Task

type Task struct {
	ID             string    `json:"id"`
	Type           string    `json:"type"`
	SpecialistName string    `json:"specialistName,omitempty"`
	Description    string    `json:"description,omitempty"`
	ParentID       string    `json:"parentId,omitempty"`
	PID            int       `json:"pid,omitempty"`
	Status         Status    `json:"status"`
	OutputFile     string    `json:"outputFile"`
	StartedAt      time.Time `json:"startedAt"`
	CompletedAt    time.Time `json:"completedAt,omitempty"`
	ExitCode       int       `json:"exitCode,omitempty"`
}

Jump to

Keyboard shortcuts

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