worker

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseWorker

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

BaseWorker runs a workload in a cancellable goroutine.

func NewBaseWorker

func NewBaseWorker(name string, logger Logger, workload Workload) *BaseWorker

NewBaseWorker creates a new worker with custom logger and workload.

func (*BaseWorker) Name

func (w *BaseWorker) Name() string

func (*BaseWorker) Start

func (w *BaseWorker) Start(ctx context.Context)

func (*BaseWorker) Stop

func (w *BaseWorker) Stop()

type Logger

type Logger interface {
	Info(format string, a ...any)
	Error(format string, a ...any)
}

Logger defines an interface for logging.

type StdLogger

type StdLogger struct{}

StdLogger is a default implementation using Go's log package.

func (StdLogger) Error

func (l StdLogger) Error(format string, a ...any)

Error logs an error message using formatting.

func (StdLogger) Info

func (l StdLogger) Info(format string, a ...any)

Info logs an informational message using formatting.

type Worker

type Worker interface {
	Start(ctx context.Context)
	Stop()
	Name() string
}

Worker defines the worker interface.

type Workload

type Workload func(ctx context.Context, log Logger)

Workload defines the task a worker should perform.

Jump to

Keyboard shortcuts

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