worker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 12 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 ModuleWorkerHandler = 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
	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,
	db database.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"`
}

Jump to

Keyboard shortcuts

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