services

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

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) *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) (mqs.Subscription, error),
	handler consumer.MessageHandler,
	concurrency int,
	logger *logging.Logger,
) 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 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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