worker

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job func(ctx context.Context) error

type Pool

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

func NewPool

func NewPool(config PoolConfig) *Pool

NewPool creates a new worker pool with auto-scaling capabilities

func (*Pool) GetMetrics

func (p *Pool) GetMetrics() poolMetrics

GetMetrics returns current pool metrics

func (*Pool) Results

func (p *Pool) Results() <-chan error

Results returns a channel for receiving job results

func (*Pool) Start

func (p *Pool) Start()

Start initializes the worker pool and starts the scaling manager

func (*Pool) Stop

func (p *Pool) Stop()

Stop gracefully shuts down the worker pool

func (*Pool) Submit

func (p *Pool) Submit(job Job)

Submit adds a job to the pool with normal priority

func (*Pool) SubmitPriority

func (p *Pool) SubmitPriority(job Job, priority int)

SubmitPriority adds a job with specified priority (higher number = higher priority)

type PoolConfig

type PoolConfig struct {
	MinWorkers    int           // Minimum number of workers
	MaxWorkers    int           // Maximum number of workers
	QueueSize     int           // Size of the job queue
	ScaleInterval time.Duration // How often to check for scaling
	IdleTimeout   time.Duration // How long a worker can be idle before shutdown
}

Jump to

Keyboard shortcuts

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