worker

package
v0.0.0-...-80ff8fe Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicHandler

func PanicHandler(logger log.Logger) func(interface{})

PanicHandler builds a panic handler for the worker pool that logs the panic.

Types

type Payload

type Payload interface {
	Execute() Resultor
}

Payload encapsulates a job and its input into a neat package to be executed by another thread.

type Pool

type Pool struct {
	*pond.WorkerPool
	// contains filtered or unexported fields
}

and other functionality to the pool.

func NewPool

func NewPool(ctx context.Context, logger log.Logger, cfg *PoolConfig) *Pool

NewPool creates a new pool.

func (*Pool) Logger

func (p *Pool) Logger() log.Logger

Logger returns the logger for the pool.

func (*Pool) Stop

func (p *Pool) Stop()

Stop stops the pool without waiting for all workers to finish. NOTE: Tasks being executed by workers will continue until completion (unless the process is terminated). Tasks in the queue will not be executed.

func (*Pool) StopAndWait

func (p *Pool) StopAndWait()

StopAndWait stops the pool and waits for all workers to finish.

type PoolConfig

type PoolConfig struct {
	// Name is the name of the pool.
	Name string
	// PrometheusPrefix is the prefix for the prometheus metrics.
	PrometheusPrefix string
	// MinWorkers is the minimum number of workers that the resizer will
	// shrink the pool down to .
	MinWorkers uint16
	// MaxWorkers is the maximum number of workers that can be active
	// at the same time.
	MaxWorkers uint16
	// ResizingStrategy is the methodology used to resize the number of workers
	// in the pool.
	ResizingStrategy string
	// MaxQueuedJobs is the maximum number of jobs that can be queued
	// before the pool starts rejecting jobs.
	MaxQueuedJobs uint16
}

PoolConfig is the configuration for a pool.

func DefaultPoolConfig

func DefaultPoolConfig() *PoolConfig

DefaultPoolConfig is the default configuration for a pool.

type Resultor

type Resultor interface {
	Result() any
	Error() error
}

Resultor encapsulates the result of a job execution.

type TaskGroup

type TaskGroup struct {
	*pond.TaskGroupWithContext
}

Jump to

Keyboard shortcuts

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