Documentation
¶
Index ¶
- Constants
- type LifecycleManager
- func (lm *LifecycleManager) AddShutdownHook(hook func() error)
- func (lm *LifecycleManager) AddStartupHook(hook func() error)
- func (lm *LifecycleManager) GetShutdownContext() context.Context
- func (lm *LifecycleManager) GracefulShutdown(timeout time.Duration) error
- func (lm *LifecycleManager) Run(errCh <-chan error) error
- func (lm *LifecycleManager) SetShutdownTimeout(d time.Duration)
Constants ¶
View Source
const DefaultShutdownTimeout = 10 * time.Second
DefaultShutdownTimeout 默认优雅关闭超时时间
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LifecycleManager ¶
type LifecycleManager struct {
// contains filtered or unexported fields
}
LifecycleManager 应用生命周期管理器
func NewLifecycleManager ¶
func NewLifecycleManager() *LifecycleManager
NewLifecycleManager 创建生命周期管理器
func (*LifecycleManager) AddShutdownHook ¶
func (lm *LifecycleManager) AddShutdownHook(hook func() error)
AddShutdownHook 添加关闭钩子
func (*LifecycleManager) AddStartupHook ¶
func (lm *LifecycleManager) AddStartupHook(hook func() error)
AddStartupHook 添加启动钩子
func (*LifecycleManager) GetShutdownContext ¶
func (lm *LifecycleManager) GetShutdownContext() context.Context
GetShutdownContext 获取关闭上下文 应用开始关闭时该 context 会被 cancel,业务方可以监听它来停止后台任务
func (*LifecycleManager) GracefulShutdown ¶
func (lm *LifecycleManager) GracefulShutdown(timeout time.Duration) error
GracefulShutdown 优雅关闭(带超时)
func (*LifecycleManager) Run ¶
func (lm *LifecycleManager) Run(errCh <-chan error) error
Run 运行生命周期:执行启动钩子,等待退出信号或运行时错误,然后优雅关闭 errCh 用于接收组件的运行时错误(如 web 服务器启动失败),收到非 nil 错误会触发关闭并返回该错误
func (*LifecycleManager) SetShutdownTimeout ¶ added in v0.3.0
func (lm *LifecycleManager) SetShutdownTimeout(d time.Duration)
SetShutdownTimeout 设置优雅关闭超时时间
Click to show internal directories.
Click to hide internal directories.