Documentation
¶
Overview ¶
SPDX-License-Identifier: AGPL-3.0-or-later
Package worker 提供统一后台任务抽象(Global Constraints #5):顺序启动、 反向排空、panic 捕获(进程不崩)。
Index ¶
- func CatchPanic(name string, log *logx.Logger)
- func GoLoop(ctx context.Context, name string, log *logx.Logger, fn func(context.Context))
- func GoRecover(name string, log *logx.Logger, fn func())
- func Loop(ctx context.Context, name string, log *logx.Logger, fn func(context.Context))
- func Recover(name string, log *logx.Logger, fn func())
- type Manager
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CatchPanic ¶
CatchPanic recovers from panic in the caller goroutine and logs Error. Usage: defer worker.CatchPanic("name", log)
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 统一装配后台任务:顺序启动、反向排空、panic 捕获(进程不崩)。 单次生命周期:StartAll/Shutdown 各只允许一次,重启需重建 Manager——复位 started 是伪修复(worker 层 startOnce 均不复位,热重启是伪需求)。
func (*Manager) Go ¶
Go 托管命名 goroutine:panic 捕获 + Warn(含栈),进程不崩。 边界(不引入"panic 后回调/重启"抽象):唯一用户 http-server 的 ListenAndServe 错误路径已有 fatalf 兜底、handler panic 由 net/http 内置 recover 兜底返回 500——回调无消费者。m.log==nil 时静默(New 恒注入, 现状全调用点恒非 nil)。
func (*Manager) Register ¶
Register 追加 worker;StartAll 已开始(started 置位)后调用返回错误—— 否则 worker 永不经 Start 却会在 Shutdown 被 Close。返回值可忽略 (main.go 调用点仅位于 StartAll 之前,恒成功)。