lifecycle

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	OnStart func(context.Context) error
	OnStop  func(context.Context) error
	// contains filtered or unexported fields
}

A Hook is a pair of start and stop callbacks, either of which can be nil, plus a string identifying the supplier of the hook.

type HookRecord added in v1.14.0

type HookRecord struct {
	CallerFrame fxreflect.Frame             // stack frame of the caller
	Func        func(context.Context) error // function that ran as sanitized name
	Runtime     time.Duration               // how long the hook ran
}

HookRecord keeps track of each Hook's execution time, the caller that appended the Hook, and function that ran as the Hook.

type HookRecords added in v1.14.0

type HookRecords []HookRecord

HookRecords is a Stringer wrapper of HookRecord slice.

func (HookRecords) Format added in v1.14.0

func (rs HookRecords) Format(w fmt.State, c rune)

Format implements fmt.Formatter to handle "%+v".

func (HookRecords) Len added in v1.14.0

func (rs HookRecords) Len() int

func (HookRecords) Less added in v1.14.0

func (rs HookRecords) Less(i, j int) bool

func (HookRecords) String added in v1.14.0

func (rs HookRecords) String() string

Used for logging startup errors.

func (HookRecords) Swap added in v1.14.0

func (rs HookRecords) Swap(i, j int)

type Lifecycle

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

Lifecycle coordinates application lifecycle hooks.

func New

func New(logger fxevent.Logger, clock fxclock.Clock) *Lifecycle

New constructs a new Lifecycle.

func (*Lifecycle) Append

func (l *Lifecycle) Append(hook Hook)

Append adds a Hook to the lifecycle.

func (*Lifecycle) RunningHookCaller added in v1.14.0

func (l *Lifecycle) RunningHookCaller() string

RunningHookCaller returns the name of the hook that was running when a Start/Stop hook timed out.

func (*Lifecycle) Start

func (l *Lifecycle) Start(ctx context.Context) error

Start runs all OnStart hooks, returning immediately if it encounters an error.

func (*Lifecycle) StartHookRecords added in v1.14.0

func (l *Lifecycle) StartHookRecords() HookRecords

StartHookRecords returns the info of OnStart hooks that successfully ran till the end, including their caller and runtime. Used to report timeout errors on Start.

func (*Lifecycle) Stop

func (l *Lifecycle) Stop(ctx context.Context) error

Stop runs any OnStop hooks whose OnStart counterpart succeeded. OnStop hooks run in reverse order.

func (*Lifecycle) StopHookRecords added in v1.14.0

func (l *Lifecycle) StopHookRecords() HookRecords

StopHookRecords returns the info of OnStop hooks that successfully ran till the end, including their caller and runtime. Used to report timeout errors on Stop.

Jump to

Keyboard shortcuts

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