procmanager

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_RUNNING    = "running"
	STATUS_RESTARTING = "restarting"
	STATUS_STOPPED    = "stopped"
	STATUS_FAILED     = "failed"
)
View Source
const DEFAULT_RESTART_DELAY = time.Second * 10

Variables

View Source
var (
	ErrProcessDuplicate     = errors.New("process is already managed by the process manager")
	ErrProcessNameDuplicate = errors.New("process with given name already exists")
	ErrProcessNotFound      = errors.New("process not found")
)

Functions

This section is empty.

Types

type Events

type Events struct {
	OnProcessExit         *event.Event[ProcessExitEvent]
	OnProcessSpawn        *event.Event[ProcessSpawnEvent]
	OnProcessForceRestart *event.Event[ProcessForceRestartEvent]
}

type ManagedProcess

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

func NewManagedProcess

func NewManagedProcess(manager *Manager, data *ProcessData) *ManagedProcess

func (*ManagedProcess) GetData

func (mp *ManagedProcess) GetData() *ProcessData

func (*ManagedProcess) GetExitState

func (mp *ManagedProcess) GetExitState() (int, time.Time, error)

func (*ManagedProcess) GetId

func (mp *ManagedProcess) GetId() string

func (*ManagedProcess) GetInnerRunningProcess

func (mp *ManagedProcess) GetInnerRunningProcess() (*os.Process, error)

func (*ManagedProcess) GetPid

func (mp *ManagedProcess) GetPid() int

func (*ManagedProcess) GetRestarts

func (mp *ManagedProcess) GetRestarts() uint32

func (*ManagedProcess) GetRunningProcess

func (mp *ManagedProcess) GetRunningProcess() (*process.Process, error)

func (*ManagedProcess) GetStatus

func (mp *ManagedProcess) GetStatus() string

func (*ManagedProcess) GetStdoutPath

func (mp *ManagedProcess) GetStdoutPath() string

func (*ManagedProcess) IsRunning

func (mp *ManagedProcess) IsRunning() bool

func (*ManagedProcess) Restart

func (mp *ManagedProcess) Restart() error

func (*ManagedProcess) Stop

func (mp *ManagedProcess) Stop() error

func (*ManagedProcess) String

func (mp *ManagedProcess) String() string

type Manager

type Manager struct {
	Processes *ProcessList
	Event     *Events
	// contains filtered or unexported fields
}

func New

func New(log logger.Logger, directories *gofu.Directories) *Manager

func (*Manager) Create

func (m *Manager) Create(data *ProcessData) (*ManagedProcess, error)

func (*Manager) Remove

func (m *Manager) Remove(process *ManagedProcess)

func (*Manager) UpdateConfiguration

func (m *Manager) UpdateConfiguration(
	process *ManagedProcess,
	update func(currentConfig *pb.ProcessConfiguration) (*pb.ProcessConfiguration, error),
) error

type ProcessData

type ProcessData struct {
	Id            string
	Configuration *pb.ProcessConfiguration
}

func (*ProcessData) GetRestartDelay

func (d *ProcessData) GetRestartDelay() time.Duration

func (*ProcessData) GetRestartPolicy

func (d *ProcessData) GetRestartPolicy() *pb.ProcessConfiguration_RestartPolicy

type ProcessExitEvent

type ProcessExitEvent struct {
	Process  *ManagedProcess
	Exited   *process.Process
	ExitCode int
}

type ProcessForceRestartEvent

type ProcessForceRestartEvent struct {
	Process    *ManagedProcess
	Spawned    *process.Process
	WasRunning bool
	Error      error
}

type ProcessList

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

ProcessList is a structure that contains a list of processes.

func NewProcessList

func NewProcessList() *ProcessList

func (*ProcessList) All

func (l *ProcessList) All() []*ManagedProcess

All returns a list of all processes. Thread-safe.

func (*ProcessList) Find

func (l *ProcessList) Find(name string) (*ManagedProcess, error)

Find returns the process with given name or pid. If process is not in the registry, returns nil. Thread-safe.

func (*ProcessList) GetById

func (l *ProcessList) GetById(id string) (*ManagedProcess, error)

GetById returns the process with given internal id. If process is not in the registry, returns nil. Thread-safe.

func (*ProcessList) GetByPid

func (l *ProcessList) GetByPid(pid int) (*ManagedProcess, error)

Get returns the process with given pid. If process is not in the registry, returns nil. Thread-safe.

type ProcessSpawnEvent

type ProcessSpawnEvent struct {
	Process *ManagedProcess
	Spawned *process.Process
	Error   error
}

Jump to

Keyboard shortcuts

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