Documentation
¶
Overview ¶
Package worker provides a configurable worker for periodic task execution with concurrency control and graceful shutdown support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(w *Worker)
Option is a function type that configures a Worker.
func WithConcurrency ¶
WithConcurrency sets the number of parallel workers. The default concurrency is 1 if not specified.
Example:
w := worker.New(myJob, worker.WithConcurrency(3))
func WithInterval ¶
WithInterval sets the time interval between job executions. The default interval is 1 second if not specified.
Example:
w := worker.New(myJob, worker.WithInterval(5*time.Second))
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker manages periodic execution of a Job with configurable concurrency.
func New ¶
New creates a new Worker with the specified Job and options. Default configuration: interval of 1 second and concurrency of 1.
Example:
w := worker.New(myJob, worker.WithInterval(2*time.Second), worker.WithConcurrency(3))
func (*Worker) Run ¶
Run starts the worker goroutines. The operation is non-blocking. Each worker runs independently and processes jobs according to the configured interval.
The context parameter controls the lifecycle of the workers. When the context is cancelled, workers will complete their current job and exit.