lifecycle

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package lifecycle holds process-lifecycle state shared between a service's main function and its HTTP layer — currently the graceful-drain signal that powers zero-downtime rolling deploys.

Ownership: main creates the Drainer and is the only caller of StartDraining (from its shutdown path). Readers (e.g. a readiness handler) take it as a narrow DrainChecker interface, so a request handler never owns or mutates process-shutdown state.

The package deliberately imports nothing beyond sync/atomic: a service that owns drain 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.

Jump to

Keyboard shortcuts

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