runner

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

README

runner

Package runner run a restart a program on signals

Variables

var (
    // ErrRunning is the return error in the Start method
    ErrRunning = errors.New("Program is already running")
    // ErrCantKill is returned by Restart and Stop in case the process can't be killed
    ErrCantKill = errors.New("Process is still alive after sending the kill signal")
    // ErrNotRunning is retuned by the Stop and Signal command when the program is not running
    ErrNotRunning = errors.New("Process is not running")
    // ErrRunnerClosed is returned by any method when the runner is closed
    ErrRunnerClosed = errors.New("Runner is closed")
)

DefaultRunnerOptions are used when no RunnerOptions are passed

var DefaultRunnerOptions = &Options{
    KillWaitPeriod: time.Second,
    ReadyString:    []string{"Listening", "Started", "Ready"},
}

Types

type EventReady

type EventReady struct { ... }

EventReady is fired whenever the command outputs the string Listening

type EventRestart

type EventRestart struct { ... }

EventRestart is fired whenever Restart is called

type EventSignal

type EventSignal struct { ... }

EventSignal is fired whenever

type EventStart

type EventStart struct { ... }

EventStart is fired whenever Start is called

type EventStarted

type EventStarted struct { ... }

EventStarted is fired whenever the subprocess is started

type EventStop

type EventStop struct { ... }

EventStop is fired whenever Stop is called

type EventStopped

type EventStopped struct { ... }

EventStopped is fired whenever the process exits

type Options

type Options struct { ... }

Options holds the runner options

type Runner

type Runner struct { ... }

Runner is an command runner that produces events on start/stop and restart

func New

func New(cmd *exec.Cmd, options *Options) *Runner

New creates a new runner for the given command if options is nil, New will use DefaultRunnerOptions

func (*Runner) Close

func (r *Runner) Close() error

Close stop all the internal goroutines After Close is called the runner can't be used anymore

func (*Runner) Restart

func (r *Runner) Restart() error

Restart restart the process by calling Stop and then Restart. If the process is not runing it will be the same as calling Start

func (*Runner) Signal

func (r *Runner) Signal(s syscall.Signal) error

Signal sends a signal to the process. If the process is not running it returns ErrNotRunning

func (*Runner) Start

func (r *Runner) Start() error

Start starts the command If the command is already running it returns ErrRunning

func (*Runner) Stop

func (r *Runner) Stop() error

Stop stops the process. It will send an interrupt signal to the process. If after KillWaitPeriod the process is still alive, it will send a kill signal


Readme created from Go doc with goreadme

Documentation

Overview

Package runner run a restart a program on signals

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRunning is the return error in the Start method
	ErrRunning = errors.New("Program is already running")
	// ErrCantKill is returned by Restart and Stop in case the process can't be killed
	ErrCantKill = errors.New("Process is still alive after sending the kill signal")
	// ErrNotRunning is retuned by the Stop and Signal command when the program is not running
	ErrNotRunning = errors.New("Process is not running")
	// ErrRunnerClosed is returned by any method when the runner is closed
	ErrRunnerClosed = errors.New("Runner is closed")
)
View Source
var DefaultRunnerOptions = &Options{
	KillWaitPeriod: time.Second,
	ReadyString:    []string{"Listening", "Started", "Ready"},
}

DefaultRunnerOptions are used when no RunnerOptions are passed

Functions

This section is empty.

Types

type EventReady

type EventReady struct {
	Data string // Data contains the block that triggered the EventReady
}

EventReady is fired whenever the command outputs the string Listening

type EventRestart

type EventRestart struct {
	// Err display any error that happen during stop
	// If Err is nil you can expect an EventStarted event
	Err error
}

EventRestart is fired whenever Restart is called

type EventSignal

type EventSignal struct {
	// Err display any error that happen during stop
	Err error
}

EventSignal is fired whenever

type EventStart

type EventStart struct {
	// Err display any error that happen during start
	// If Err is nil you can expect an EventStarted event
	Err error
}

EventStart is fired whenever Start is called

type EventStarted added in v0.0.4

type EventStarted struct {
	Command string
}

EventStarted is fired whenever the subprocess is started

type EventStop

type EventStop struct {
	// Err display any error that happen during stop
	Err error
}

EventStop is fired whenever Stop is called

type EventStopped

type EventStopped struct {
	Output   []string // Holds the command output up to MaxOutputSize
	ExitCode int      // ExitCode holds the exit code
	RunTime  time.Duration
}

EventStopped is fired whenever the process exits

type Options

type Options struct {
	KillWaitPeriod time.Duration // Time wait for a proces to die before callking kill
	ReadyString    []string      // ReadyString is the string that Runner looks for in the command output to send EventReady
}

Options holds the runner options

type Runner

type Runner struct {
	Events <-chan (interface{}) // Events will be fired here. The channel is not expected to be closed.
	// contains filtered or unexported fields
}

Runner is an command runner that produces events on start/stop and restart

func New

func New(cmd *exec.Cmd, options *Options) *Runner

New creates a new runner for the given command if options is nil, New will use DefaultRunnerOptions

func (*Runner) Close

func (r *Runner) Close() error

Close stop all the internal goroutines After Close is called the runner can't be used anymore

func (*Runner) Restart

func (r *Runner) Restart() error

Restart restart the process by calling Stop and then Restart. If the process is not runing it will be the same as calling Start

func (*Runner) Signal

func (r *Runner) Signal(s syscall.Signal) error

Signal sends a signal to the process. If the process is not running it returns ErrNotRunning

func (*Runner) Start

func (r *Runner) Start() error

Start starts the command If the command is already running it returns ErrRunning

func (*Runner) Stop

func (r *Runner) Stop() error

Stop stops the process. It will send an interrupt signal to the process. If after KillWaitPeriod the process is still alive, it will send a kill signal

Jump to

Keyboard shortcuts

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