worker

package
v0.0.7-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWorkerError

func NewWorkerError(workerName string) *workerError

Types

type BaseWorker

type BaseWorker struct {
	Queue       workqueue.TypedRateLimitingInterface[Operand]
	WorkerName  string
	WorkerError WorkerError

	Env string
	// contains filtered or unexported fields
}

BaseWorker implements generic functionalities for a worker. Actual workers types are supposed to embed this type in them.

func NewBaseWorker

func NewBaseWorker(workerName string, env string) BaseWorker

func (*BaseWorker) EnqueueAfter

func (w *BaseWorker) EnqueueAfter(operand Operand, after time.Duration)

Clients call this method to enqueue a worker after the passed duration.

func (*BaseWorker) EnqueueNow

func (w *BaseWorker) EnqueueNow(operand Operand)

Clients call this method to enqueue work to a worker immeadiately.

func (*BaseWorker) Logger

func (w *BaseWorker) Logger() logger.Logger

func (*BaseWorker) Name

func (w *BaseWorker) Name() string

func (*BaseWorker) WorkQueue

type Operand

type Operand interface{}

func ToOperandList

func ToOperandList[T any](in ...T) []Operand

type PeriodicReconcilable

type PeriodicReconcilable interface {
	Interval() time.Duration
}

If a worker implements PeriodicReconcilable, the worker manager would run enqueue GetInput()'s result to the worker's work queue every Interval().

type Result

type Result struct {
	Requeue bool

	// RequeueAfter if greater than 0, tells the worker manager to requeue the operand after the Duration.
	// Implies that Requeue is true, there is no need to set Requeue to true at the same time as RequeueAfter.
	RequeueAfter time.Duration
}

Result contains the result of a worker's Execute invocation.

func (*Result) IsZero

func (r *Result) IsZero() bool

IsZero returns true if this result is empty.

type Worker

type Worker interface {
	Execute(ctx context.Context, operand Operand) (Result, *errors.ServiceError)
	EnqueueNow(operand Operand)
	EnqueueAfter(Operand Operand, after time.Duration)
	WorkQueue() workqueue.TypedRateLimitingInterface[Operand]
	// Function that returns the list of operands to be passed to the workers execute method.
	GetInput(context.Context) ([]Operand, *errors.ServiceError)
	Logger() logger.Logger
	Name() string
}

Workers both run periodically at `Interval()` and when clients call `EnqueueNow()`.

type WorkerError

type WorkerError interface {
	NewError(format string, args ...any) *errors.ServiceError
}

Directories

Path Synopsis
Package release is a generated GoMock package.
Package release is a generated GoMock package.
Package stack is a generated GoMock package.
Package stack is a generated GoMock package.

Jump to

Keyboard shortcuts

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