lifecycle

package
v0.0.0-...-d95a457 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStackTrace

func GetStackTrace(all bool) string

func InstallStackTracer

func InstallStackTracer() stopper.Stopper

for debugging, show goroutine trace on receipt of USR1. uninstall by calling Stop on the returned object

Types

type Lifecycle

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

A Lifecycle manages some boilerplate for running daemons.

func New

func New(singleProcess bool) *Lifecycle

New creates a new Lifecycle. This should be called after validating parameters but before starting work or allocating external resources. A startup message is displayed and shutdown handlers for SIGINT and SIGTERM are registered.

If New is passed 'true' for singleProcess, it will wait for existing duplicate processes to exit before returning.

func (*Lifecycle) AddKillFunc

func (l *Lifecycle) AddKillFunc(f func())

AddKillFunc will add f to the list of functions to be ran when the lifecycle is killed. Functions passed to AddKillFunc are ran in reverse order, much like defer. If the lifecycle is being killed ad the same time AddKillFunc is called, the passed function will not be called.

func (*Lifecycle) FatalQuit

func (l *Lifecycle) FatalQuit()

FatalQuit will kill the lifecycle to continue into the RunWhenKilled function.

func (*Lifecycle) RunWhenKilled

func (l *Lifecycle) RunWhenKilled(finalizer func(), timeout time.Duration)

RunWhenKilled blocks until a shutdown signal is received, then executes finalizer and only returns either after it has finished or another shutdown signal is received. If timeout is non-zero, RunWhenKilled will force shutdown if the finalizer cannot complete within the timeout duration.

RunWhenKilled should only be called once with a master function to run on program shutdown.

RunWhenKilled runs the finalizer before any deferred AddKillFunc functions. This is so that the finalizer can begin the shutdown process that any other AddKillFunc functions can rely on.

Jump to

Keyboard shortcuts

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