Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrChannelClosed = errors.Base("channel closed")
)
View Source
var (
ErrNotTask error = errors.Base("task pool entity is not a task")
)
Functions ¶
func InitPrometheus ¶ added in v0.5.9
func InitPrometheus(reg prometheus.Registerer)
Initialise Prometheus metrics for this module.
Types ¶
type Config ¶
type Config struct {
// Custom queue to use.
InputQueue TaskQueue
// Prometheus registerer.
Prometheus prometheus.Registerer
// Function to use as the worker.
WorkerFunc TaskFn
// Function to use to determine scaling.
ScalerFunc ScalerFn
// Worker pool name for logger and metrics.
Name string
// Minimum number of workers.
MinWorkers int64
// Maximum number of workers.
MaxWorkers int64
// Idle timeout duration.
IdleTimeout time.Duration
// Drain target duration.
DrainTarget time.Duration
}
func NewConfigWithQueue ¶ added in v1.0.6
Create a new configuration with a custom queue.
func (*Config) SetIdleTimeout ¶ added in v1.0.6
Set the idle timeout value.
func (*Config) SetScalerFunction ¶ added in v1.0.6
Set the scaler function.
func (*Config) SetWorkerFunction ¶ added in v1.0.6
Set the worker function.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task structure.
type TaskQueue ¶ added in v1.0.6
type TaskQueue interface {
Put(context.Context, *Task) error
Get(context.Context) (*Task, error)
Len() int
}
func NewChanTaskQueue ¶ added in v1.0.6
func NewQueueTaskQueue ¶ added in v1.0.6
type WorkerPool ¶
type WorkerPool interface {
// Start the worker pool.
Start()
// Stop the worker pool.
Stop()
// Submit a task to the worker pool.
Submit(UserData) error
// Return the number of current workers in the pool.
WorkerCount() int64
// Return the minimum number of workers in the pool.
MinWorkers() int64
// Return the maximum number of workers in the pool.
MaxWorkers() int64
// Set the minimum number of workers to the given value.
SetMinWorkers(int64)
// Set the maximum number of workers to the given value.
SetMaxWorkers(int64)
// Set the task callback function.
SetTaskFunction(TaskFn)
// Set the task scaler function.
SetScalerFunction(ScalerFn)
// Return the name of the pool.
Name() string
}
Worker pool interface.
func NewWorkerPool ¶
func NewWorkerPool(ctx context.Context, config *Config) WorkerPool
Create a new worker pool.
The provided context must have `logger.Logger` in its user value. See `contextdi` and `logger.SetLogger`.
Click to show internal directories.
Click to hide internal directories.