Documentation
¶
Overview ¶
Package node is the service's one lifecycle model: a tree of nodes, each with a name, a logger, an instrumentation scope, start and stop hooks, its own goroutines and an optional readiness probe.
The SDK's own parts (config, listeners, presence) and the author's components and dependencies are nodes of the same tree. Start walks the tree depth-first in creation order; Stop walks it back in exact reverse, so a node always stops before anything created ahead of it — a component before the dependency it uses, a child before its parent.
Stopping a node cancels its context, runs its stop hooks in reverse, then waits for its goroutines. A node whose start failed is stopped too: stop hooks must tolerate a partial start.
Index ¶
- Constants
- Variables
- type Condition
- type Group
- type Kind
- type Node
- func (n *Node) Budget(fn func(context.Context) (context.Context, context.CancelFunc))
- func (n *Node) Child(name string, kind Kind, optional bool) *Node
- func (n *Node) Children() []*Node
- func (n *Node) Condition() (Condition, bool)
- func (n *Node) Env() any
- func (n *Node) Failed() <-chan error
- func (n *Node) Go(fn func(context.Context) error)
- func (n *Node) Kind() Kind
- func (n *Node) Log() *xlog.Logger
- func (n *Node) Name() string
- func (n *Node) OnStart(fn func(context.Context) error)
- func (n *Node) OnStop(fn func(context.Context) error)
- func (n *Node) Optional() bool
- func (n *Node) Path() string
- func (n *Node) ProbeInterval() time.Duration
- func (n *Node) Readiness() probe.Probe
- func (n *Node) Ready(p probe.Probe)
- func (n *Node) Scope() *xtrace.Scope
- func (n *Node) SetCondition(fn func() Condition)
- func (n *Node) SetProbeInterval(d time.Duration)
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Stop(ctx context.Context) error
- func (n *Node) Walk(fn func(*Node))
- type Tree
Constants ¶
const DefaultProbeInterval = 5 * time.Second
DefaultProbeInterval is the ProbeInterval of a tree that sets none.
Variables ¶
var ( ErrStopTimeout = lifecycle.ErrStopTimeout ErrPanic = lifecycle.ErrPanic )
Lifecycle errors are shared with xshutdown.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is one element of the tree.
func New ¶
New creates a tree and returns its service root. env is service-wide data any node can reach through Env.
func (*Node) Child ¶
Child creates a node under n. Names are unique within a namespace: a duplicate path gets a numeric suffix. After Start only a starting parent may create children (a dependency building its internals); anything else is a programming error and panics.
func (*Node) ProbeInterval ¶
ProbeInterval is how often the service evaluates its health.
func (*Node) Readiness ¶
Readiness is the readiness of n's subtree, evaluated on every check so nodes created during start count too.
func (*Node) SetCondition ¶
SetCondition installs what Condition reports.
func (*Node) SetProbeInterval ¶
SetProbeInterval sets how often the service evaluates its health, for nodes that check something periodically; d <= 0 keeps the default.