lifecycle

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lifecycle holds process-lifecycle state shared between a service's main function and its HTTP layer: the start-up gate (Starter) that holds a replica out of the pool until every module has started, and the graceful-drain signal (Drainer) that powers zero-downtime rolling deploys.

Ownership: main creates both and is the only caller of MarkReady (once start-up is complete) and StartDraining (from its shutdown path). Readers (e.g. a readiness handler) take them as the narrow ReadyChecker and DrainChecker interfaces, so a request handler never owns or mutates process-lifecycle state.

The package deliberately imports nothing beyond sync/atomic: a service that owns lifecycle state but runs no infra server can depend on it without pulling in an HTTP framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DrainChecker

type DrainChecker interface {
	// IsDraining reports whether the process has begun graceful shutdown.
	IsDraining() bool
}

DrainChecker is the read-only view of drain state that request handlers depend on. Keeping handlers behind this interface means they can report "not ready" without knowing anything about how shutdown is orchestrated.

type Drainer

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

Drainer is the single source of truth for whether this process is draining. The zero value is ready to use and safe for concurrent access.

func NewDrainer

func NewDrainer() *Drainer

NewDrainer returns a Drainer in the not-draining state.

func (*Drainer) IsDraining

func (d *Drainer) IsDraining() bool

IsDraining implements DrainChecker.

func (*Drainer) StartDraining

func (d *Drainer) StartDraining()

StartDraining marks the process as draining. The transition is one-way: there is no un-drain, because draining only ever precedes process exit. Idempotent and safe for concurrent use.

type ReadyChecker added in v0.5.1

type ReadyChecker interface {
	// IsReady reports whether main has declared start-up complete.
	IsReady() bool
}

ReadyChecker is the read-only view of start-up state that request handlers depend on. It mirrors DrainChecker: a readiness handler can hold traffic back until start-up has finished without being able to declare it finished.

type Starter added in v0.5.1

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

Starter is the single source of truth for whether this process has finished starting up. The zero value is ready to use, safe for concurrent access and NOT ready: a replica must opt in to traffic, never fall into it.

Why an explicit flag rather than deriving readiness from the probes: during start-up the probes either pass too early (a module that has no probe is still initializing, so the load balancer sends traffic to a half-started replica) or fail (500 plus an error log line on every health-check poll for the whole start-up). Neither tells the truth. Only main knows when every module has started, so only main can say so — and then readiness does not depend on the order in which modules initialize.

Ownership: main creates the Starter and is the only caller of MarkReady, once every module has started. Readers take it as a ReadyChecker.

It is a separate type from Drainer on purpose. Folding a "started" flag into Drainer would leave every existing Drainer user that never calls MarkReady reporting not-ready forever.

func NewStarter added in v0.5.1

func NewStarter() *Starter

NewStarter returns a Starter in the not-ready state.

func (*Starter) IsReady added in v0.5.1

func (s *Starter) IsReady() bool

IsReady implements ReadyChecker.

func (*Starter) MarkReady added in v0.5.1

func (s *Starter) MarkReady()

MarkReady declares start-up complete. The transition is one-way: there is no un-ready, because leaving the pool later is what draining is for. Idempotent and safe for concurrent use.

Jump to

Keyboard shortcuts

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