Documentation
¶
Overview ¶
worker/manager_metrics.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrQueueFull = errors.New("queue is full")
ErrQueueFull is returned when the pool queue is full.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates multiple workers, providing restart and panic recovery.
func NewManager ¶
func NewManager(logger *slog.Logger, opts ...ManagerOption) *Manager
type ManagerMetrics ¶
type ManagerMetrics struct {
// contains filtered or unexported fields
}
func NewManagerMetrics ¶
func NewManagerMetrics(reg prometheus.Registerer) *ManagerMetrics
type ManagerOption ¶
type ManagerOption func(*Manager)
func WithInitialDelay ¶
func WithInitialDelay(d time.Duration) ManagerOption
WithInitialDelay overrides the base backoff delay (default 1s).
func WithManagerMetrics ¶
func WithManagerMetrics(metrics *ManagerMetrics) ManagerOption
func WithMaxRestarts ¶
func WithMaxRestarts(n int) ManagerOption
WithMaxRestarts sets the maximum number of consecutive failures before the worker is permanently stopped. 0 means unlimited (default).
type Metrics ¶
type Metrics interface {
TasksSubmitted(ctx context.Context)
TasksRejected(ctx context.Context)
TasksPanicked(ctx context.Context)
}
Metrics defines counters for the worker pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a bounded worker pool. It runs a fixed number of worker goroutines and accepts jobs up to a fixed queue size. Submitting a job never spawns a new goroutine; if the queue is full Submit returns ErrQueueFull.
func New ¶
New creates a new Pool using functional options. Defaults: workers=1, queueSize=workers, logger=slog.Default().
func (*Pool) Close ¶
func (p *Pool) Close()
Close closes the job queue, signalling workers to drain any remaining jobs and then exit. It is safe to call Close concurrently and it is idempotent. After Close, Submit will return ErrQueueFull for new jobs. Call Wait after Close to block until all workers have stopped.