Documentation ¶
Overview ¶
Package workers provides general purpose worker mechanism that outputs stacktrace when given job panics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEnqueueAfterWorkerShutdown is returned when job is given after worker context cancellation. ErrEnqueueAfterWorkerShutdown = errors.New("job can not be enqueued after worker shutdown") // ErrQueueOverflow is returned when job is given, but all workers are busy and queue is full. ErrQueueOverflow = errors.New("queue is full") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { WorkerNum uint `json:"worker_num" yaml:"worker_num"` QueueSize uint `json:"queue_size" yaml:"queue_size"` SuperviseInterval time.Duration `json:"supervise_interval" yaml:"supervise_interval"` }
Config contains some configuration variables. Use NewConfig to construct Config instance with default value and feed the instance to json.Unmarshal or yaml.Unmarshal to override.
type Reporter ¶
Reporter is an interface to report statistics such as queue length to outer service. Implement this to pass statistical variables in desired way. e.g. Report stats to prometheus via exporter
type Stats ¶ added in v1.3.0
type Stats struct { // QueueSize is the size of queued task to work. // Use this value to adjust Config.QueueSize. QueueSize int }
Stats represents a group of statistical data. This can be passed to Reporter.Report() to report current state.
type Worker ¶
type Worker interface {
Enqueue(func()) error
}
Worker is an interface that all Worker implementation must satisfy. Worker implementation can be fed to sarah.Runner via sarah.RunnerOption as below.
myWorker := NewMyWorkerImpl() option := sarah.WithWorker(myWorker) runner, _ := sarah.NewRunner(sarah.NewConfig(), option)
type WorkerOption ¶
type WorkerOption func(*worker) error
WorkerOption defines function that worker's functional option must satisfy.
func WithReporter ¶
func WithReporter(reporter Reporter) WorkerOption
WithReporter creates and returns WorkerOption to set preferred Reporter implementation.