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

appready

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package appready defines what "app-ready" means for a bundle install (P7-PLUG-19, cap:cli.bundle-app-ready) and runs the steps after the plugin files are on disk.

Purpose: `nself bundle install` used to end at one build. This package names the nine steps (licence, fetch, install, ledger, reconcile, start, readiness, tracking, health), records each one with its result and duration, stops at the first failure and says which step and which plugin failed. Inputs: Hooks (cmd-supplied reconcile / start / Hasura / service-health functions, injected because this package may not import those layers) and the Members read from the installed plugin.json files. Outputs: a Report (human text through Render, JSON through the struct tags). Constraints: nothing here applies SQL or touches a database; HTTP goes through internal/plugin/readiness (internal/httptimeout); the dry run only prints.

Index

Constants

View Source
const (
	StepLicence   = "licence"
	StepFetch     = "fetch"
	StepInstall   = "install"
	StepLedger    = "ledger"
	StepReconcile = "reconcile"
	StepStart     = "start"
	StepReadiness = "readiness"
	StepTracking  = "tracking"
	StepHealth    = "health"
)

Step names, in the order they run. These exact strings are used in the human output, in the JSON and in E135 messages.

View Source
const (
	ResultOK      = "ok"
	ResultFailed  = "failed"
	ResultSkipped = "skipped"
	ResultPlanned = "planned" // dry run
)

Step results.

View Source
const NotVerifiedV15 = "not verified (v1.5 behaviour, NSELF_V15=1)"

NotVerifiedV15 is the detail of every step that did not run because the install built no start hook (v1.4 default mode).

Variables

View Source
var ErrNoProject = errors.New("not in an nSelf project")

ErrNoProject is what Hooks.Reconcile returns outside an nSelf project: the plugins are installed, but there is no stack to reconcile, start or check.

Order is the fixed step order.

Functions

func DefaultHealthURL

func DefaultHealthURL(m Member) string

DefaultHealthURL is where the member's container publishes /health on the host.

func Missing

func Missing(members []Member, tracked map[string]bool) (string, []string)

Missing returns, for the first member (in order) that has untracked tables, that member's name and the sorted missing tables.

func PrintPlan

func PrintPlan(w io.Writer, bundle string, members []string)

PrintPlan lists the nine steps for a dry run. It writes nothing but text.

func Render

func Render(w io.Writer, r Report)

Render writes one line per step, then the verdict line: APP-READY, or NOT APP-READY naming the step and plugin, or the Note.

func TrackedTables

func TrackedTables(raw []byte) (map[string]bool, error)

TrackedTables parses an export_metadata response into the set of tracked postgres tables, keyed "schema.name". It reads sources[].tables[].table and, for older metadata, a top-level tables array. Only postgres-kind sources count (kind "postgres", "citus", "cockroach", or no kind); a data-connector or BigQuery source is ignored. A table entry counts only in the {schema,name} object form (schema defaults to public); any other shape is skipped.

Types

type Failure

type Failure struct {
	Step   string
	Plugin string
	Err    error
}

Failure is the first failed step.

type Hooks

type Hooks struct {
	// Reconcile regenerates project files for the new membership.
	Reconcile func(ctx context.Context) error
	// Start boots the stack (the in-process `nself start`).
	Start func(ctx context.Context) error
	// ExportMetadata returns Hasura's export_metadata response.
	ExportMetadata func(ctx context.Context) ([]byte, error)
	// ServiceHealth returns an error listing unhealthy services.
	ServiceHealth func(ctx context.Context) error
	// HealthURL is the plugin's /health URL; default http://127.0.0.1:<port><endpoint>.
	HealthURL func(m Member) string
	// Timeout bounds each waiting step; default readiness.TimeoutFromEnv().
	Timeout time.Duration
	// Interval is the poll interval; tests set milliseconds.
	Interval time.Duration
}

Hooks are the project-level operations the post-install steps call. A nil function skips its step and marks the report unverified.

type Member

type Member struct {
	Name             string
	Dir              string
	Port             int
	HealthEndpoint   string
	Tables           []string
	BootMigrations   bool // manifest declares migrations.apply: boot
	HasMigrationsDir bool // a migrations directory exists on disk
}

Member is one installed plugin of the bundle.

func LoadMembers

func LoadMembers(pluginDir string, names []string) ([]Member, error)

LoadMembers reads the named plugins' manifests from pluginDir.

type Outcome

type Outcome struct {
	// Reconciled is true once the Reconcile hook ran, success or not.
	Reconciled bool
}

Outcome tells the caller what Run did beyond the Report.

func Run

func Run(ctx context.Context, rn *Runner, h Hooks, pluginDir string, names []string, changed bool) Outcome

Run executes reconcile .. health. changed is whether bundle membership changed; with no change reconcile is skipped (start and the checks still run).

type Report

type Report struct {
	Bundle    string       `json:"bundle"`
	AppReady  bool         `json:"app_ready"`
	Steps     []StepResult `json:"steps"`
	Failed    string       `json:"failed_step,omitempty"`
	FailedFor string       `json:"failed_plugin,omitempty"`
	// Note explains a report that is neither app-ready nor failed (for example
	// the install ran outside an nSelf project).
	Note string `json:"note,omitempty"`
}

Report is the outcome of one bundle install.

type Runner

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

Runner times each step and stops at the first failure: once a step has failed, every later step is recorded as skipped.

func NewRunner

func NewRunner(bundle string) *Runner

NewRunner returns a Runner for bundle.

func (*Runner) Failure

func (r *Runner) Failure() *Failure

Failure returns the first failure, or nil.

func (*Runner) Record

func (r *Runner) Record(name, result string, d time.Duration, detail string)

Record stores a step that already ran outside the Runner (the fetch step runs before the plan is printed). A failed result makes it the run's first failure unless one is already set.

func (*Runner) Report

func (r *Runner) Report() Report

Report assembles the report in canonical order. A step that never ran is listed as skipped. AppReady is true only when no step failed and nothing marked the run Unverified, so a run that could not check a step is never called ready.

func (*Runner) Skip

func (r *Runner) Skip(name, detail string)

Skip records a step that did not run.

func (*Runner) Step

func (r *Runner) Step(name string, fn func() (string, error)) error

Step runs fn as the named step. After a failure it does not run fn and records the step as skipped. fn returns a detail text and an error; wrap the error in *StepError to name the plugin.

func (*Runner) Unverified

func (r *Runner) Unverified(reason string)

Unverified marks the run as not proven app-ready without failing it (the first reason is kept).

type StepError

type StepError struct {
	Plugin string
	Err    error
}

StepError is the error a step returns to say which plugin it failed for.

func (*StepError) Error

func (e *StepError) Error() string

func (*StepError) Unwrap

func (e *StepError) Unwrap() error

type StepResult

type StepResult struct {
	Name       string `json:"name"`
	Result     string `json:"result"`
	DurationMS int64  `json:"duration_ms"`
	Detail     string `json:"detail,omitempty"`
}

StepResult is one line of the report.

Jump to

Keyboard shortcuts

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