Documentation ¶
Overview ¶
Package graceful provides a mechanism to gracefully stop processes on os signals.
Index ¶
- Variables
- func Background(opts ...BackgroundOption) context.Context
- func MaybeDebugf(log Logger, format string, args ...interface{})
- func MaybeErrorf(log Logger, format string, args ...interface{})
- func MaybeInfof(log Logger, format string, args ...interface{})
- func Notify(signals ...os.Signal) chan os.Signal
- func NotifyWithCapacity(capacity int, signals ...os.Signal) chan os.Signal
- func Shutdown(hosted ...Graceful) error
- func ShutdownByContext(ctx context.Context, hosted ...Graceful) error
- func ShutdownBySignal(hosted []Graceful, opts ...ShutdownOption) error
- type BackgroundOption
- type BackgroundOptions
- type Graceful
- type Logger
- type ShutdownOption
- type ShutdownOptions
Constants ¶
This section is empty.
Variables ¶
DefaultShutdownSignals are the default os signals to capture to shut down.
Functions ¶
func Background ¶ added in v1.20210306.2
func Background(opts ...BackgroundOption) context.Context
Background yields a context that will signal `<-ctx.Done()` when a signal is sent to the process (as specified in `DefaultShutdownSignals`).
func MaybeDebugf ¶ added in v1.20210316.2
MaybeDebugf calls the logger debugf method if the logger is set.
func MaybeErrorf ¶ added in v1.20210316.2
MaybeErrorf calls the logger errorf method if the logger is set.
func MaybeInfof ¶ added in v1.20210316.2
MaybeInfof calls the logger infof method if the logger is set.
func Notify ¶ added in v1.20201204.1
Notify returns a channel that listens for a given set of os signals.
func NotifyWithCapacity ¶ added in v1.20210316.2
NotifyWithCapacity returns a channel with a given capacity that listens for a given set of os signals.
func Shutdown ¶
Shutdown racefully stops a set hosted processes based on SIGINT or SIGTERM received from the os. It will return any errors returned by Start() that are not caused by shutting down the server. A "Graceful" processes *must* block on start.
func ShutdownByContext ¶ added in v1.20210701.2
ShutdownByContext gracefully stops a set hosted processes based on context cancellation.
func ShutdownBySignal ¶
func ShutdownBySignal(hosted []Graceful, opts ...ShutdownOption) error
ShutdownBySignal gracefully stops a set hosted processes based on a set of variadic options. A "Graceful" processes *must* block on start. Fatal errors will be returned, that is, errors that are returned by either .Start() or .Stop(). Panics are not caught by graceful, and it is assumed that your .Start() or .Stop methods will catch relevant panics.
Types ¶
type BackgroundOption ¶ added in v1.20210316.2
type BackgroundOption func(*BackgroundOptions)
BackgroundOption mutates background options
func OptBackgroundLog ¶ added in v1.20210316.2
func OptBackgroundLog(log Logger) BackgroundOption
OptBackgroundLog sets the logger.
func OptBackgroundSignals ¶ added in v1.20210316.2
func OptBackgroundSignals(signals ...os.Signal) BackgroundOption
OptBackgroundSignals sets the signals.
func OptBackgroundSkipStopOnSignal ¶ added in v1.20210316.2
func OptBackgroundSkipStopOnSignal(skipStopOnSignal bool) BackgroundOption
OptBackgroundSkipStopOnSignal sets if we should stop the signal channel on stop.
type BackgroundOptions ¶ added in v1.20210316.2
BackgroundOptions are options for the background context.
type Logger ¶ added in v1.20210316.2
type Logger interface { Infof(format string, args ...interface{}) Debugf(format string, args ...interface{}) Errorf(format string, args ...interface{}) }
Logger is a type that can be used as a graceful process logger.
type ShutdownOption ¶ added in v1.20201204.1
type ShutdownOption func(*ShutdownOptions)
ShutdownOption is a mutator for shutdown options.
func OptDefaultShutdownSignal ¶ added in v1.20201204.1
func OptDefaultShutdownSignal() ShutdownOption
OptDefaultShutdownSignal returns an option that sets the shutdown signal to the defaults.
func OptShutdownSignal ¶ added in v1.20201204.1
func OptShutdownSignal(signal chan os.Signal) ShutdownOption
OptShutdownSignal sets the shutdown signal.
type ShutdownOptions ¶ added in v1.20201204.1
ShutdownOptions are the options for graceful shutdown.