simplesignalhandler

package
v0.0.0-...-ac56535 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package simplesignalhandler provides a worker that responds to os signals and returns a pre-defined error from this worker when the signal is received.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns the dependency manifold for this worker based on the config provided.

Types

type Logger

type Logger interface {
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
}

type ManifoldConfig

type ManifoldConfig struct {
	// SignalCh is a preconfigured channel listening for signals.
	SignalCh <-chan os.Signal

	// DefaultHandlerError is the default error to return from this worker when
	// there is no mapping for the received signal. Value must be specified.
	DefaultHandlerError error

	// HandlerErrors is a map of os.Signal to error returns from this worker.
	// Valid for this map to be nil or empty.
	HandlerErrors map[os.Signal]error

	// Logger to use for this worker
	Logger Logger
}

ManifoldConfig is responsible for configuring this worker.

func (ManifoldConfig) Start

func (m ManifoldConfig) Start(context dependency.Context) (worker.Worker, error)

Start is responsible for creating a new worker for the manifold config.

func (ManifoldConfig) Validate

func (m ManifoldConfig) Validate() error

Validate validates the manifold config.

type SignalHandlerFunc

type SignalHandlerFunc func(os.Signal) error

SignalHandlerFunc is func definition for returning an error based on a received signal.

func SignalHandler

func SignalHandler(defaultErr error, signalMap map[os.Signal]error) SignalHandlerFunc

SignalHandler is a default implementation that uses signal mapping and a default error.

type SignalWatcher

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

SignalWatcher is the worker responsible for watching signals and returning the appropriate error from a handler.

func NewSignalWatcher

func NewSignalWatcher(
	logger Logger,
	sig <-chan os.Signal,
	handler SignalHandlerFunc,
) (*SignalWatcher, error)

NewSignalWatcher constructs a new signal watcher worker with the specified signal channel and handler func.

func (*SignalWatcher) Kill

func (s *SignalWatcher) Kill()

Kill implements worker.Kill

func (*SignalWatcher) Wait

func (s *SignalWatcher) Wait() error

Wait implements worker.Wait

Jump to

Keyboard shortcuts

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