xputil

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRtError          = errors.New("")
	ErrNoRoutines       = fmt.Errorf("%wno routines loaded", ErrRtError)
	ErrInvalidRoutine   = fmt.Errorf("%winvalid routine name", ErrRtError)
	ErrDuplicateRoutine = fmt.Errorf("%wduplicate routine name", ErrRtError)
	ErrRoutineActive    = fmt.Errorf("%wroutine is active", ErrRtError)
)

Functions

func PanicExcept

func PanicExcept(f func() error) (err error, trace string)

run function f, return err and trace if function panics

func SetProcTitle

func SetProcTitle(title string) error

set process title in OS process table, max 16 char

Types

type BaseProcess

type BaseProcess struct {
	*BaseTasklet

	// process title as shown in OS process table
	ProcTitle string
	// contains filtered or unexported fields
}

func NewBaseProcess

func NewBaseProcess(log *xlog.Logger, tsk Tasklet) *BaseProcess

func (*BaseProcess) SetSignal

func (pr *BaseProcess) SetSignal(sig os.Signal, fn SignalHandler)

func (*BaseProcess) Start

func (pr *BaseProcess) Start()

type BaseRoutine

type BaseRoutine struct {
	*BaseTasklet
	Name string
	// contains filtered or unexported fields
}

func NewBaseRoutine

func NewBaseRoutine(tsk Tasklet) *BaseRoutine

func (*BaseRoutine) IsAlive

func (rt *BaseRoutine) IsAlive() bool

func (*BaseRoutine) Parent

func (rt *BaseRoutine) Parent() *RtManager

func (*BaseRoutine) Setup

func (rt *BaseRoutine) Setup(name string, rm *RtManager) error

func (*BaseRoutine) Start

func (rt *BaseRoutine) Start()

type BaseTasklet

type BaseTasklet struct {
	Log *xlog.Logger

	// error delay for execution loop
	ErrorDelay float64
	// contains filtered or unexported fields
}

func NewTaskletManager

func NewTaskletManager(log *xlog.Logger, tsk Tasklet) *BaseTasklet

func (*BaseTasklet) IsKillEvent

func (tl *BaseTasklet) IsKillEvent() bool

func (*BaseTasklet) IsTermEvent

func (tl *BaseTasklet) IsTermEvent() bool

func (*BaseTasklet) Kill

func (tl *BaseTasklet) Kill()

func (*BaseTasklet) Sleep

func (tl *BaseTasklet) Sleep(timeout float64) bool

func (*BaseTasklet) Start

func (tl *BaseTasklet) Start()

func (*BaseTasklet) Stop

func (tl *BaseTasklet) Stop()

type CommandHandler added in v0.3.6

type CommandHandler func(string) (string, error)

command handling callback function definition args: manager handler, received command return: reply message and error

type ExtRtManager

type ExtRtManager struct {
	*RtManager

	// management pipes path and handlers
	PipeDir string

	// pipe read polling delay
	PollInterval float64

	// command handler callback function
	CommandHandler CommandHandler
	// contains filtered or unexported fields
}

extended routine manager with management through named pipes manager uses 2 pipes: 1 for input and 1 for output

func NewExtRtManager

func NewExtRtManager(log *xlog.Logger) *ExtRtManager

func (*ExtRtManager) CheckCommand

func (rm *ExtRtManager) CheckCommand() error

func (*ExtRtManager) Execute

func (rm *ExtRtManager) Execute() error

func (*ExtRtManager) Initialize

func (rm *ExtRtManager) Initialize() error

func (*ExtRtManager) Terminate

func (rm *ExtRtManager) Terminate() error

type Routine

type Routine interface {
	Setup(string, *RtManager) error
	Parent() *RtManager
	IsAlive() bool
	Start()
	Stop()
	Kill()
}

type RtManager

type RtManager struct {
	*BaseProcess

	// routines monitoring interval in sec
	MonInterval float64
	// delay to wait for routine terminate in sec
	TermDelay float64
	// contains filtered or unexported fields
}

func NewRtManager

func NewRtManager(log *xlog.Logger) *RtManager

func (*RtManager) AddRoutine

func (rm *RtManager) AddRoutine(name string, rt Routine, active bool) error

add new routine handler to manager

func (*RtManager) CheckRoutines

func (rm *RtManager) CheckRoutines() error

monitor routines and start/stop as per each routine status

func (*RtManager) DelRoutine

func (rm *RtManager) DelRoutine(name string) error

delete routine handler from manager

func (*RtManager) Execute

func (rm *RtManager) Execute() error

run manager operations

func (*RtManager) Initialize

func (rm *RtManager) Initialize() error

initialize manager

func (*RtManager) ListRoutines

func (rm *RtManager) ListRoutines() []string

return name list of all current loaded routines

func (*RtManager) RestartRoutine

func (rm *RtManager) RestartRoutine(name string) error

restart routine

func (*RtManager) StartRoutine

func (rm *RtManager) StartRoutine(name string) error

start routine

func (*RtManager) StopRoutine

func (rm *RtManager) StopRoutine(name string) error

stop routine

func (*RtManager) Terminate

func (rm *RtManager) Terminate() error

terminate manager

type SignalHandler

type SignalHandler func()

type Tasklet

type Tasklet interface {
	Initialize() error
	Execute() error
	Terminate() error
}

Jump to

Keyboard shortcuts

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