Help us shape the future of Go! Take the 2026 Go Developer Survey

readiness

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package readiness verifies that a plugin has applied its own boot-time migrations (contract:plugin.boot-migrations v1, ADR 0010).

Purpose: the CLI never applies plugin SQL. A plugin applies its migrations when it boots (sdk/go/migrate) and serves {"migrations":{"applied":n, "expected":m}} in its /health JSON. Install and update flows call Wait to block, bounded, until applied == expected; `nself doctor` calls Probe once.

Inputs: the plugin name (for messages), its /health URL and a timeout. Outputs: nil when ready, otherwise a *errs.CLIError naming the plugin: E118 when the wait ended with applied < expected (or the plugin never answered), E119 when /health has no valid migrations field. A cancelled caller context returns the context error, not E118. Constraints: every wait is bounded (a non-positive timeout is an error); HTTP goes through internal/httptimeout; nothing here touches the database.

Index

Constants

View Source
const (
	// DefaultTimeout bounds Wait when NSELF_PLUGIN_READY_TIMEOUT is unset.
	DefaultTimeout = 120 * time.Second
	// EnvTimeout overrides DefaultTimeout (integer seconds, or a Go duration such as 3m).
	EnvTimeout = "NSELF_PLUGIN_READY_TIMEOUT"
)

Variables

This section is empty.

Functions

func IsUnreachable

func IsUnreachable(err error) bool

IsUnreachable reports whether err is a "plugin did not answer /health" error from Probe (as opposed to an E119 contract violation).

func TimeoutFromEnv

func TimeoutFromEnv() (time.Duration, error)

TimeoutFromEnv returns the wait bound: EnvTimeout when set, else DefaultTimeout. An unparseable or non-positive value is an error, never a silent default.

func Wait

func Wait(ctx context.Context, plugin, healthURL string, timeout time.Duration, opts ...Option) error

Wait polls healthURL until the plugin reports applied == expected, for at most timeout. It returns E119 at once when /health lacks the migrations field, and E118 (naming the plugin and both numbers) when the timeout ends first. Callers read the bound with TimeoutFromEnv.

Types

type Option

type Option func(*config)

Option tunes Wait.

func WithClient

func WithClient(h *http.Client) Option

WithClient sets the HTTP client (default httptimeout.WithTimeout(5 s)).

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the poll interval (default 2 s).

type Progress

type Progress struct {
	Applied  int
	Expected int
}

Progress is the migrations status a plugin serves in /health.

func Probe

func Probe(ctx context.Context, client *http.Client, plugin, healthURL string) (Progress, error)

Probe reads a plugin's /health once and returns its migrations progress. A plugin that answers 200 without a valid migrations field gets E119; a plugin that does not answer (connection error, non-200) gets an error for which IsUnreachable is true.

func (Progress) Ready

func (p Progress) Ready() bool

Ready reports whether every expected migration is applied.

Jump to

Keyboard shortcuts

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