processkit

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package processkit provides a standard-library process boundary for Modary applications: deterministic probes, pre-shutdown drain, active-request admission, and one shared HTTP server lifecycle. It contains no database, container-platform, or telemetry dependency.

Index

Constants

View Source
const (
	// DefaultCheckTimeout bounds one complete readiness evaluation.
	DefaultCheckTimeout = 2 * time.Second
	// MaximumChecks bounds the number of selected readiness dependencies.
	MaximumChecks = 32
)
View Source
const (
	// DefaultReadHeaderTimeout bounds receipt of request headers.
	DefaultReadHeaderTimeout = 5 * time.Second
	// DefaultReadTimeout bounds receipt of the complete request.
	DefaultReadTimeout = 30 * time.Second
	// DefaultWriteTimeout bounds writing the complete response.
	DefaultWriteTimeout = 30 * time.Second
	// DefaultIdleTimeout bounds keep-alive connection idleness.
	DefaultIdleTimeout = 60 * time.Second
	// DefaultMaxHeaderBytes bounds request headers to one MiB.
	DefaultMaxHeaderBytes = 1 << 20
	// MaximumHeaderBytes is the largest configurable request-header boundary.
	MaximumHeaderBytes = 16 << 20
)
View Source
const DefaultShutdownTimeout = 10 * time.Second

DefaultShutdownTimeout bounds server drain and application cleanup.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, options ServerOptions) (resultErr error)

Serve listens, marks the process ready, serves until cancellation or failure, transitions readiness before shutdown, drains accepted requests, and then stops application resources under one timeout.

Types

type BuildInfo

type BuildInfo struct {
	Version  string
	Revision string
	Created  string
}

BuildInfo is immutable process identity injected by the consumer build. It deliberately excludes host, user, and other high-cardinality dimensions.

func NormalizeBuildInfo

func NormalizeBuildInfo(info BuildInfo) (BuildInfo, error)

NormalizeBuildInfo validates bounded identity and supplies explicit local development defaults.

func (BuildInfo) LogValue

func (info BuildInfo) LogValue() slog.Value

LogValue groups build identity in structured diagnostics.

type Check

type Check struct {
	Name string
	Run  func(context.Context) error
}

Check is one bounded readiness dependency. Check functions must be safe for concurrent use and honor cancellation. Manager permits at most one in-flight invocation per check, preventing a noncooperative dependency from creating an unbounded goroutine count across repeated probes.

type Manager

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

Manager owns process readiness and accepted HTTP work.

func New

func New(options Options) (*Manager, error)

New validates and defensively copies readiness checks.

func (*Manager) BeginDrain

func (manager *Manager) BeginDrain()

BeginDrain atomically disables readiness and new application admission. Repeated calls are safe.

func (*Manager) Drain

func (manager *Manager) Drain(ctx context.Context) error

Drain begins drain and waits for accepted application requests.

func (*Manager) LivenessHandler

func (manager *Manager) LivenessHandler() http.Handler

LivenessHandler reports only local process state and never calls a remote dependency.

func (*Manager) MarkReady

func (manager *Manager) MarkReady() error

MarkReady enables traffic after application assembly and listener startup.

func (*Manager) MarkStopped

func (manager *Manager) MarkStopped() error

MarkStopped records terminal local shutdown. It is valid only after drain.

func (*Manager) Middleware

func (manager *Manager) Middleware(next http.Handler) (http.Handler, error)

Middleware admits application requests only while ready. Exact probe paths remain reachable while draining so an orchestrator can observe the transition.

func (*Manager) Phase

func (manager *Manager) Phase() Phase

Phase returns the current local lifecycle state.

func (*Manager) ReadinessHandler

func (manager *Manager) ReadinessHandler() http.Handler

ReadinessHandler runs bounded selected dependency checks only while the local lifecycle is ready.

type Options

type Options struct {
	CheckTimeout time.Duration
	Checks       []Check
}

Options controls readiness behavior.

type Phase

type Phase string

Phase is the local admission lifecycle. Draining remains live but rejects new application work and reports unready.

const (
	// PhaseStarting rejects traffic before assembly and listener startup finish.
	PhaseStarting Phase = "starting"
	// PhaseReady admits application traffic and enables dependency readiness.
	PhaseReady Phase = "ready"
	// PhaseDraining rejects new work while accepted work completes.
	PhaseDraining Phase = "draining"
	// PhaseStopped is the terminal process state after resources are released.
	PhaseStopped Phase = "stopped"
)

type ServerOptions

type ServerOptions struct {
	Address           string
	Handler           http.Handler
	Manager           *Manager
	Logger            *slog.Logger
	Shutdown          func(context.Context) error
	ShutdownTimeout   time.Duration
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	Build             BuildInfo
}

ServerOptions is the shared generated HTTP process contract.

Jump to

Keyboard shortcuts

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