worker

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTask = errors.New("no task found")
View Source
var SuppressedError = errors.New("suppressed error")

Functions

func WithMaxConcurrentTasksLimit

func WithMaxConcurrentTasksLimit(limit int) func(*WorkerOptions)

func WithPollerBackoffMultiplier

func WithPollerBackoffMultiplier(multiplier float64) func(*WorkerOptions)

func WithPollerInitialBackoffInterval

func WithPollerInitialBackoffInterval(duration time.Duration) func(*WorkerOptions)

func WithPollerMaxBackoffInterval

func WithPollerMaxBackoffInterval(duration time.Duration) func(*WorkerOptions)

Types

type Summarizer

type Summarizer interface {
	Summary() any
}

type TaskProcessor

type TaskProcessor[T Summarizer, R Summarizer] interface {
	GetTask(ctx context.Context) (T, error)
	ProcessTask(ctx context.Context, task T) (R, error)
	CompleteTask(ctx context.Context, result R) error
	AbandonTask(ctx context.Context, task T, reason *string) error
}

type Worker

type Worker[T Summarizer, R Summarizer] interface {
	Start(ctx context.Context)
	Stop(ctx context.Context)
}

func NewWorker

func NewWorker[T Summarizer, R Summarizer](
	name string,
	taskProcessor TaskProcessor[T, R],
	logger *zap.Logger,
	options *WorkerOptions,
) Worker[T, R]

func NewWorkerOpts

func NewWorkerOpts[T Summarizer, R Summarizer](
	name string,
	taskProcessor TaskProcessor[T, R],
	logger *zap.Logger,
	opts ...func(*WorkerOptions),
) Worker[T, R]

type WorkerOptions

type WorkerOptions struct {
	MaxConcurrentTasksLimit      int
	PollerInitialBackoffInterval time.Duration
	PollerMaxBackoffInterval     time.Duration
	PollerBackoffMultiplier      float64
}

func NewWorkerOptions

func NewWorkerOptions() *WorkerOptions

type WorkerThread

type WorkerThread[T Summarizer, R Summarizer] struct {
	// contains filtered or unexported fields
}

func NewWorkerThread

func NewWorkerThread[T Summarizer, R Summarizer](
	name string,
	taskProcessor TaskProcessor[T, R],
	bo backoff.Backoff,
	wg *sync.WaitGroup,
	logger *zap.Logger,
) *WorkerThread[T, R]

func (*WorkerThread[T, R]) Run

func (w *WorkerThread[T, R]) Run(ctx context.Context)

Jump to

Keyboard shortcuts

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