runner

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package runner provides an application lifecycle manager for coordinated startup and graceful shutdown.

Services are registered in two tiers: infrastructure (database, cache, queue) and core (API handlers). Infrastructure services start first; if any fail, the application exits immediately. Core services start afterward. On shutdown, core services stop first, then infrastructure. The entire shutdown is bounded by a configurable timeout (default 30 seconds). Service panics are caught and logged.

Basic usage:

r := runner.New(
    runner.WithInfrastructureService(dbService),
    runner.WithInfrastructureService(cacheService),
    runner.WithCoreService(apiServer),
    runner.WithShutdownTimeout(30*time.Second),
)
r.Run() // Blocks until SIGINT/SIGTERM; calls os.Exit(1) on error

Each service must implement the Service interface (Start, Stop, Name). Startup failures in any tier abort the application immediately.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServicePanic   = errors.New("runner: service panicked")
	ErrServiceFailed  = errors.New("runner: service failed to start")
	ErrShutdownTimout = errors.New("runner: shutdown timeout exceeded")
)

Functions

This section is empty.

Types

type Option

type Option func(*Runner)

func WithCoreService

func WithCoreService(svc Service) Option

func WithInfrastructureService

func WithInfrastructureService(svc Service) Option

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

type Runner

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

func New

func New(opts ...Option) *Runner

func (*Runner) Run

func (r *Runner) Run()

type Service

type Service interface {
	Start(ctx context.Context) error
	Stop() error
	Name() string
}

Jump to

Keyboard shortcuts

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