lifecycle

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package lifecycle manages VORTEX's process lifecycle: ordered startup, signal handling, and graceful shutdown (build plan M1.4).

Two POSIX signals are meaningful to VORTEX:

  • SIGTERM (and SIGINT): begin a graceful shutdown. Registered shutdown hooks run in reverse registration order — last-registered first — so dependencies are torn down before the things they depend on.
  • SIGHUP: request a configuration hot-reload (vortex.cue is re-validated and re-applied without dropping connections). Registered reload hooks fire.

On Windows, where SIGHUP and SIGTERM do not exist, only os.Interrupt (Ctrl+C) is wired up; the reload path can still be driven programmatically via Reload. This keeps the package buildable and testable on every platform the binary targets while behaving correctly on Linux servers in production.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Logger receives lifecycle events. Required.
	Logger *slog.Logger
	// ShutdownTimeout bounds how long all shutdown hooks together may take.
	// Defaults to 30s if zero.
	ShutdownTimeout time.Duration
}

Config configures a Manager.

type Hook

type Hook func(ctx context.Context) error

Hook is a unit of shutdown or reload work. The context carries the deadline for the operation; hooks should respect it and return promptly.

type Manager

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

Manager coordinates signal handling and graceful shutdown. The zero value is not ready for use; construct one with New.

func New

func New(cfg Config) *Manager

New constructs a Manager.

func (*Manager) Done

func (m *Manager) Done() <-chan struct{}

Done returns a channel closed once Run has finished its shutdown sequence.

func (*Manager) OnReload

func (m *Manager) OnReload(name string, fn Hook)

OnReload registers a hook to run when a SIGHUP (or Reload call) requests a configuration hot-reload. Hooks run in registration order.

func (*Manager) OnShutdown

func (m *Manager) OnShutdown(name string, fn Hook)

OnShutdown registers a hook to run during graceful shutdown. Hooks run in reverse registration order. name is used in logs.

func (*Manager) Reload

func (m *Manager) Reload()

Reload triggers the reload hooks programmatically (used by tests and by the CLI `vortex reload` path on platforms without SIGHUP).

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run blocks until a shutdown signal arrives or the supplied context is cancelled, handling reload signals along the way. It then runs all shutdown hooks and returns. Run is intended to be the last call in main.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown initiates a graceful shutdown programmatically (e.g. from the Windows /internal/shutdown endpoint, which has no SIGTERM to send). If Run is currently blocking, Shutdown signals it to unblock and run the shutdown hooks itself; otherwise (no Run active, as in unit tests) Shutdown runs the hooks directly. Safe to call multiple times.

Jump to

Keyboard shortcuts

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