dynworker

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotTask error = errors.Base("task pool entity is not a task")
)

Functions

func InitPrometheus added in v0.5.9

func InitPrometheus()

Initialise Prometheus metrics for this module.

Types

type Config

type Config struct {
	Name        string          // Worker pool name for logger and metrics.
	MinWorkers  int64           // Minimum number of workers.
	MaxWorkers  int64           // Maximum number of workers.
	Logger      logger.Logger   // Logger instance.
	Parent      context.Context // Parent context.
	IdleTimeout time.Duration   // Idle timeout duration.
}

func NewConfig

func NewConfig(
	ctx context.Context,
	lgr logger.Logger,
	name string,
	minw, maxw int64,
) *Config

Create a new configuration.

func NewDefaultConfig

func NewDefaultConfig() *Config

Create a new default configuration.

func (*Config) SetItleTimeout

func (obj *Config) SetItleTimeout(timeout time.Duration)

Set the idle timeout value.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task structure.

func NewTask added in v0.5.9

func NewTask(ctx context.Context, lgr logger.Logger, data UserData) *Task

func (*Task) Data added in v0.5.9

func (obj *Task) Data() UserData

Get the user-supplied data for the task.

func (*Task) Logger added in v0.5.9

func (obj *Task) Logger() logger.Logger

Get the logger instance for the task.

func (*Task) Parent added in v0.5.9

func (obj *Task) Parent() context.Context

Get the parent context for the task.

type TaskFn

type TaskFn func(*Task) error

Task callback function type.

type UserData added in v0.5.9

type UserData any

User-supplied data.

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)
}

Worker pool interface.

func NewWorkerPool

func NewWorkerPool(config *Config, workfn TaskFn) WorkerPool

Create a new worker pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL