Documentation ¶
Overview ¶
Package lifecycle provides a life cycle manager abstracting the starting and stopping of processes by registered start or stop hooks.
The following features as supported:
- Start hooks can either be called synchronously or asynchronously.
- Start hooks can use the application context (hard shutdown) or background context (graceful shutdown).
- Stop hooks are synchronous and use a shutdown context with 10s timeout.
- Ordering of start and stop hooks.
- Any error from start hooks immediately triggers graceful shutdown.
- Closing application context triggers graceful shutdown.
- Any error from stop hooks immediately triggers hard shutdown.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HookFuncCtx ¶
HookFuncCtx wraps a context (no error) hook function as a IHookFunc.
type HookFuncErr ¶
type HookFuncErr func() error
HookFuncErr wraps an error (no context) hook function as a IHookFunc.
type HookFuncMin ¶
type HookFuncMin func()
HookFuncMin wraps a minimum (no context, no error) hook function as a IHookFunc.
type HookStartType ¶
type HookStartType int
HookStartType defines the type of start hook.
const ( // AsyncAppCtx defines a start hook that will be called asynchronously (non-blocking) // with the application context. Using the application usually results in hard shutdown. AsyncAppCtx HookStartType = iota + 1 // SyncBackground defines a start hook that wil be called synchronously (blocking) // with a fresh background context. Processes that support graceful shutdown can // associate this with a call to RegisterStop. SyncBackground // AsyncBackground defines a start hook that wil be called asynchronously (non-blocking) // with a fresh background context. Processes that support graceful shutdown can // associate this with a call to RegisterStop. AsyncBackground )
type IHookFunc ¶
IHookFunc is the life cycle hook function interface. Users will mostly wrap functions using one of the types below.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages process life cycle by registered start and stop hooks.
func (*Manager) RegisterStart ¶
func (m *Manager) RegisterStart(typ HookStartType, order OrderStart, fn IHookFunc)
RegisterStart registers a start hook. The type defines whether it is sync or async and which context is used. The order defines the order in which hooks are called.
func (*Manager) RegisterStop ¶
RegisterStop registers a synchronous stop hook that will be called with the shutdown context that may timeout.
type OrderStart ¶
type OrderStart int
OrderStart defines the order hooks are started.
const ( StartAggSigDB OrderStart = iota StartRelay StartMonitoringAPI StartValidatorAPI StartP2PPing StartP2PConsensus StartSimulator StartScheduler )
Global ordering of start hooks.
func (OrderStart) String ¶
func (i OrderStart) String() string
type OrderStop ¶
type OrderStop int
OrderStop defines the order hooks are stopped.
const ( StopScheduler OrderStop = iota // High level components... StopRetryer StopDutyDB StopBeaconMock // Close this before validator API, since it can hold long-lived connections. StopValidatorAPI StopTracing // Low level services... StopP2PPeerDB StopP2PTCPNode StopP2PUDPNode StopMonitoringAPI )
Global ordering of stop hooks; follows dependency tree from root to leaves.