Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrQueueFull 表示任务队列已满,无法接受新任务。 // 调用者应该处理此错误(例如:返回 503,或者降级)。 ErrQueueFull = errors.New("task: queue is full") // ErrRunnerClosed 表示 Runner 已经停止或正在停止,不再接受新任务。 ErrRunnerClosed = errors.New("task: runner is closed") )
Functions ¶
Types ¶
type ErrorHandler ¶
ErrorHandler 用于处理任务执行过程中的 Panic 或错误。 ctx: 发生错误时的上下文 p: recover() 捕获的对象 (可能为 nil)
type Option ¶
type Option func(*config)
Option 定义配置修改函数
func WithErrorHandler ¶
func WithErrorHandler(h ErrorHandler) Option
WithErrorHandler 设置 Panic 处理回调。 建议在此处集成 zap/zerolog 等日志库。
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner 是一个并发限制的任务执行器。
type Stats ¶
type Stats struct {
// 配置参数
MaxWorkers int `json:"max_workers"`
QueueSize int `json:"queue_size"`
// 实时状态
ActiveWorkers int64 `json:"active_workers"` // 当前正在执行任务的 Worker 数
QueuedTasks int `json:"queued_tasks"` // 当前排队等待的任务数
// 累积计数 (自启动以来)
TotalProcessed uint64 `json:"total_processed"` // 成功处理的任务数
TotalPanics uint64 `json:"total_panics"` // 发生的 Panic 总数
TotalRefused uint64 `json:"total_refused"` // 因队列满被拒绝的任务数
}
Stats 包含 Runner 的运行时快照
Click to show internal directories.
Click to hide internal directories.