services

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthHandler

func HealthHandler(supervisor *worker.WorkerSupervisor) gin.HandlerFunc

HealthHandler creates a health check handler that reports worker supervisor health

func NewBaseRouter

func NewBaseRouter(supervisor *worker.WorkerSupervisor, ginMode string, pprofEnabled bool) *gin.Engine

NewBaseRouter creates a base router with health check endpoint This is used by all services to expose /healthz

TODO: Rethink API versioning strategy in the future. For now, we expose health check at both /healthz and /api/v1/healthz for backwards compatibility. The /api/v1 prefix is hardcoded here but should be part of a broader versioning approach.

func NewConsumerWorker

func NewConsumerWorker(
	name string,
	subscribe func(ctx context.Context, opts ...mqs.SubscribeOption) (mqs.Subscription, error),
	handler consumer.MessageHandler,
	concurrency int,
	logger *logging.Logger,
	opts ...ConsumerWorkerOption,
) worker.Worker

NewConsumerWorker creates a new generic consumer worker.

func NewHTTPServerWorker

func NewHTTPServerWorker(server *http.Server, logger *logging.Logger) worker.Worker

NewHTTPServerWorker creates a new HTTP server worker.

func NewRetryMQWorker

func NewRetryMQWorker(scheduler scheduler.Scheduler, logger *logging.Logger) worker.Worker

NewRetryMQWorker creates a new retry scheduler worker.

Types

type ConsumerWorker

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

ConsumerWorker is a generic worker that wraps a message queue consumer. It handles subscription at runtime and consistent error handling for graceful shutdowns.

func (*ConsumerWorker) Name

func (w *ConsumerWorker) Name() string

Name returns the worker name.

func (*ConsumerWorker) Run

func (w *ConsumerWorker) Run(ctx context.Context) error

Run starts the consumer and blocks until context is cancelled or it fails.

type ConsumerWorkerOption added in v1.6.0

type ConsumerWorkerOption func(*ConsumerWorker)

ConsumerWorkerOption configures a ConsumerWorker.

func WithMaxConsecutiveErrors added in v1.6.0

func WithMaxConsecutiveErrors(n int) ConsumerWorkerOption

WithMaxConsecutiveErrors sets how many receive errors in a row end a run. Defaults to the consumer package default.

type HTTPServerWorker

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

HTTPServerWorker wraps an HTTP server as a worker.

func (*HTTPServerWorker) Name

func (w *HTTPServerWorker) Name() string

Name returns the worker name.

func (*HTTPServerWorker) Run

func (w *HTTPServerWorker) Run(ctx context.Context) error

Run starts the HTTP server and blocks until context is cancelled or server fails.

type RetryMQWorker

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

RetryMQWorker wraps a retry scheduler as a worker.

func (*RetryMQWorker) Name

func (w *RetryMQWorker) Name() string

Name returns the worker name.

func (*RetryMQWorker) Run

func (w *RetryMQWorker) Run(ctx context.Context) error

Run starts the retry scheduler monitor and blocks until context is cancelled or it fails.

type ServiceBuilder

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

ServiceBuilder constructs workers based on service configuration.

func NewServiceBuilder

func NewServiceBuilder(ctx context.Context, cfg *config.Config, logger *logging.Logger, telemetry telemetry.Telemetry) *ServiceBuilder

NewServiceBuilder creates a new ServiceBuilder.

func (*ServiceBuilder) BuildAPIWorkers

func (b *ServiceBuilder) BuildAPIWorkers(baseRouter *gin.Engine) error

BuildAPIWorkers creates the API router and registers workers for the API service. This sets up the infrastructure, creates the API router, and registers workers: 1. Retry scheduler 2. PublishMQ consumer (optional) The baseRouter parameter is extended with API routes (apirouter already has health check)

func (*ServiceBuilder) BuildDeliveryWorker

func (b *ServiceBuilder) BuildDeliveryWorker(baseRouter *gin.Engine) error

BuildDeliveryWorker creates and registers the delivery worker.

func (*ServiceBuilder) BuildLogWorker

func (b *ServiceBuilder) BuildLogWorker(baseRouter *gin.Engine) error

BuildLogWorker creates and registers the log worker.

func (*ServiceBuilder) BuildWorkers

func (b *ServiceBuilder) BuildWorkers() (*worker.WorkerSupervisor, error)

BuildWorkers builds workers based on the configured service type and returns the supervisor.

func (*ServiceBuilder) Cleanup

func (b *ServiceBuilder) Cleanup(ctx context.Context)

Cleanup runs all registered cleanup functions for all services. Cleanup is performed in LIFO (last-in-first-out) order to ensure that resources created later (which may depend on earlier resources) are cleaned up before their dependencies.

Jump to

Keyboard shortcuts

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