workerpool

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCleanupPeriod

func WithCleanupPeriod(cleanupPeriod time.Duration) func(*workerPool)

WithCleanupPeriod option sets the cleanup period for the worker pool

func WithIdleTimeout

func WithIdleTimeout(idleTimeout time.Duration) func(*workerPool)

WithIdleTimeout option sets the idle timeout for the worker pool

Types

type Worker

type Worker interface {
	// Work triggers the worker to work and returns true if it did work, false otherwise.
	// The worker's idle time is calculated based on the return value of this method
	Work() bool

	// SleepDurations returns the sleep durations for the worker (min, max), i.e. how long the worker should sleep if it has no work to do
	SleepDurations() (min, max time.Duration)

	// Stop stops the worker and waits until all its goroutines have stopped
	Stop()
}

Worker is a worker that can be pinged for work and stopped by the worker pool when it is idle

type WorkerPool

type WorkerPool interface {
	// PingWorker instructs the pool to ping the worker for the given partition
	PingWorker(partition string)

	// Shutdown stops all workers in the pool and waits for them to stop
	Shutdown()

	// Size returns the number of workers in the pool
	Size() int
}

WorkerPool manages a pool of workers and their lifecycle

func New

func New(ctx context.Context, workerSupplier WorkerSupplier, logger logger.Logger, opts ...func(*workerPool)) WorkerPool

New creates a new worker pool

type WorkerSupplier

type WorkerSupplier func(partition string) Worker

WorkerSupplier is a function able to create a new worker for the given partition

Jump to

Keyboard shortcuts

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