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
Use RunContext instead of Run to supply your own context and receive an error instead of exiting the process (e.g. for custom signal handling).
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 ¶
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Runner)
func WithCoreService ¶
func WithShutdownTimeout ¶
func WithStartupGracePeriod ¶ added in v1.4.0
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) RunContext ¶ added in v1.4.0
RunContext starts all registered services and blocks until ctx is cancelled or any service fails. Either event triggers a graceful shutdown (core services first, then infrastructure). It returns nil on a clean cancellation-triggered shutdown and the service failure otherwise.
Most applications should use Run, which wires SIGINT/SIGTERM handling and exits the process on failure. RunContext is for callers that manage their own signals or exit codes, and for tests.