worker

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCodeWorkerError = "WORKER_ERROR"
View Source
var ErrWorkerHandlerNoWorkers = errors.Newf("WORKER_HANDLER_NO_WORKERS", "worker handler has no workers")
View Source
var ErrWorkerHandlerStopped = errors.Newf("WORKER_HANDLER_STOPPED", "worker handler stopped")
View Source
var FxExport = di.FxProvideAs[Handler](
	NewLongRunningWorkerHandlerFx,
	nil,
	[]fx.Annotation{fx.ResultTags(`group:"worker_handlers"`)},
)

Functions

func GetWorkerID

func GetWorkerID(ctx log.ValueContext) (string, bool)

func GetWorkerName

func GetWorkerName(ctx log.ValueContext) (string, bool)

func NewWorkerContext

func NewWorkerContext(
	parentCtx context.Context,
	name string,
	id string,
) context.Context

NewWorkerContext creates a new child context with worker info and a configured logger with the worker name and id. Dependencies should be added to the context using NewContextWithDeps.

func ProvideAsLongRunningWorker

func ProvideAsLongRunningWorker(provider any, anns ...fx.Annotation) fx.Option

Types

type ConcurrencyConfig

type ConcurrencyConfig struct {
	Mode          ConcurrencyMode
	SingleLockTTL time.Duration
}

type ConcurrencyMode

type ConcurrencyMode int
const (
	ConcurrencyModeMulti  ConcurrencyMode = iota
	ConcurrencyModeSingle ConcurrencyMode = iota
)

func (ConcurrencyMode) String

func (i ConcurrencyMode) String() string

type Handler

type Handler interface {
}

type LongRunningWorker

type LongRunningWorker interface {
	GetName() string
	GetID() string
	GetConcurrency() ConcurrencyConfig
	GetRetry() RetryConfig
	Run(ctx context.Context) error
}

type LongRunningWorkerHandler

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

func NewLongRunningWorkerHandler

func NewLongRunningWorkerHandler(
	conf config.Config,
	lf log.LoggerFactory,
	dbGORM databasegorm.DB,
	dbBun *bun.DB,
	fxLifecycle fx.Lifecycle,
	fxShutdowner fx.Shutdowner,
	dlFactory distributedlock.Factory,
	workers []LongRunningWorker,
) *LongRunningWorkerHandler

func (*LongRunningWorkerHandler) Run

Run runs all workers asynchronously and blocks until all workers are done. It returns error if any of the workers returns error from LongRunningWorker.Run

func (*LongRunningWorkerHandler) Start

func (h *LongRunningWorkerHandler) Start()

Start starts all workers asynchronously and returns immediately

func (*LongRunningWorkerHandler) Stop

type LongRunningWorkerHandlerParams

type LongRunningWorkerHandlerParams struct {
	di.BaseParams
	DLFactory distributedlock.Factory
	Workers   []LongRunningWorker `group:"long_running_workers"`
}

type RetryConfig added in v0.7.0

type RetryConfig struct {
	NoTransientError     bool          // Do not retry on transient errors.
	AllErrors            bool          // Retry on all errors, including non-transient errors
	Delay                time.Duration // Delay before retrying, zero means use default delay of 1 second.
	MaxRetries           int           // Max retry times, zero means use default max retry of 3 times.
	ResetRetryCountDelay time.Duration // How long after a run without error before the retry count is reset, zero means use default of 1 second.
}

func (RetryConfig) GetDelay added in v0.7.0

func (rc RetryConfig) GetDelay() time.Duration

func (RetryConfig) GetMaxRetries added in v0.7.0

func (rc RetryConfig) GetMaxRetries() int

func (RetryConfig) GetResetRetryCountDelay added in v0.7.0

func (rlc RetryConfig) GetResetRetryCountDelay() time.Duration

Jump to

Keyboard shortcuts

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