funrun

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package funrun provides a simple way to run multiple processes in a single process group.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdStatus

type CmdStatus int

A command's status

const (
	CmdNotStarted CmdStatus = iota // The command hasn't started yet
	CmdRunning                     // The command is running
	CmdDone                        // The command has finished successfully
	CmdFailed                      // The command has finished with an error
	CmdStopped                     // The command has been stopped
)

type Command

type Command struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(conf *ProcConf) *Command

func (*Command) Cancel

func (c *Command) Cancel()

func (*Command) Error

func (c *Command) Error() error

func (*Command) Name

func (c *Command) Name() string

func (*Command) Run

func (c *Command) Run(ctx context.Context) error

func (*Command) SetOutputs

func (c *Command) SetOutputs(wout, werr *PrefixWriter)

func (*Command) Status

func (c *Command) Status() CmdStatus

type Conf

type Conf struct {
	Procs []*ProcConf `yaml:"procs"`
}

func ReadConf

func ReadConf(path string) (*Conf, error)

type Manager

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

func NewManager

func NewManager(conf *Conf) *Manager

func (*Manager) Cancel

func (m *Manager) Cancel()

func (*Manager) Error

func (m *Manager) Error() error

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

func (*Manager) SetOutputs

func (m *Manager) SetOutputs(wout, werr io.Writer)

func (*Manager) Shutdown

func (m *Manager) Shutdown()

type MapError

type MapError map[string]error

func (MapError) Error

func (m MapError) Error() string

type PrefixWriter

type PrefixWriter struct {
	Name   string
	Color  termenv.ANSIColor
	Writer io.Writer
	sync.Mutex
}

func NewPrefixWriter

func NewPrefixWriter(name, outType string, nameWidth, color int, write io.Writer) *PrefixWriter

func (*PrefixWriter) Close

func (w *PrefixWriter) Close() error

func (*PrefixWriter) Logf

func (w *PrefixWriter) Logf(s string, a ...any) error

func (*PrefixWriter) Logln

func (w *PrefixWriter) Logln(s string) error

func (*PrefixWriter) Write

func (w *PrefixWriter) Write(p []byte) (int, error)

type ProcConf

type ProcConf struct {
	Name      string            `json:"name,omitempty" yaml:"name,omitempty"`             // Name of the process
	Cmd       string            `json:"cmd,omitempty" yaml:"cmd,omitempty"`               // Command to run (required unless Cmds is set)
	Cmds      []string          `json:"cmds,omitempty" yaml:"cmds,omitempty"`             // Command to run (required unless Cmd is set)
	Args      []string          `json:"args,omitempty" yaml:"args,omitempty"`             // Arguments to pass to the command
	Envs      map[string]string `json:"envs,omitempty" yaml:"envs,omitempty"`             // Environment variables to set
	Restart   RestartPolicy     `json:"restart,omitempty" yaml:"restart,omitempty"`       // Restart policy for the command
	WorkDir   string            `json:"workdir,omitempty" yaml:"workdir,omitempty"`       // Working directory for the command
	ClearEnvs bool              `json:"clear_envs,omitempty" yaml:"clear_envs,omitempty"` // Clear all environment variables before setting the ones in Envs

	Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"` // Timeout for the command
}

type RestartPolicy

type RestartPolicy string

RestartPolicy represents the restart behavior of a process.

const (
	RestartNever  RestartPolicy = "never"   // Never restart the process
	RestartOnFail RestartPolicy = "on-fail" // Restart the process if it exits with a non-zero exit code
	RestartAlways RestartPolicy = "always"  // Always restart the process
)

type SyncWriter

type SyncWriter struct {
	Writer io.Writer
	sync.Mutex
}

SyncWriter is a wrapper around an io.Writer that is safe for concurrent use.

func (*SyncWriter) Write

func (w *SyncWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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