worker

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWorker

func RunWorker[T runnable](name string, opts ...Option) any

RunWorker creates an fx.Invoke that registers and starts a worker for the given dependency type. The dependency must have a Run(ctx context.Context) error method.

Options:

  • WithReady(): wait for all components to be ready before starting
  • WithTrafficReady(): wait for traffic readiness before starting
  • WithShutdown(): trigger application shutdown on fatal error

Example:

fx.Invoke(
    worker.RunWorker[*reader]("reader", worker.WithTrafficReady(), worker.WithShutdown()),
    worker.RunWorker[*processor]("processor", worker.WithReady()),
)

Types

type Option

type Option func(*Options)

Option is a functional option for configuring a worker.

func WithReady

func WithReady() Option

WithReady makes the worker wait for all components to be ready before starting.

func WithShutdown

func WithShutdown() Option

WithShutdown makes the worker trigger application shutdown on fatal error.

func WithTrafficReady

func WithTrafficReady() Option

WithTrafficReady makes the worker wait for traffic readiness before starting.

type Options

type Options struct {
	WaitForTrafficReady bool
	WaitReady           bool
	ShutdownOnError     bool
}

Options contains configuration for a worker.

Jump to

Keyboard shortcuts

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