supervisor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 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 supervisor runs the Angelia roles (api, scheduler, worker, dispatcher) inside one process, serves /healthz and /readyz, and shuts everything down gracefully on cancellation.

Index

Constants

View Source
const DefaultDrainTimeout = 25 * time.Second

DefaultDrainTimeout is how long roles and the HTTP server get, in total, to finish in-flight work after shutdown starts. It must stay below the Kubernetes terminationGracePeriodSeconds (30s by default).

View Source
const DefaultWriteTimeout = 10 * time.Second

DefaultWriteTimeout is the HTTP server's write timeout.

Variables

This section is empty.

Functions

func RoleNames

func RoleNames() []string

RoleNames returns every role name in start order.

Types

type Factory

type Factory func(name string) Role

Factory builds the Role for a name. Real roles replace the stubs as their stories land.

type HTTPRole

type HTTPRole interface {
	Mount(mux *http.ServeMux)
}

HTTPRole is implemented by roles that serve HTTP routes. The supervisor owns the single listener and calls Mount before it starts serving, so roles share the port with /healthz and /readyz.

type ReadyChecker

type ReadyChecker interface {
	Ready(ctx context.Context) error
}

ReadyChecker reports whether the instance can serve work, for example the database is reachable and migrations are applied. A non-nil error means not ready.

type ReadyFunc

type ReadyFunc func(ctx context.Context) error

ReadyFunc adapts a function to ReadyChecker.

func (ReadyFunc) Ready

func (f ReadyFunc) Ready(ctx context.Context) error

Ready implements ReadyChecker.

type Role

type Role interface {
	Name() string
	Run(ctx context.Context) error
}

Role is one long-running part of the process. Run blocks until ctx is cancelled (then returns nil or a context error after finishing or releasing in-flight work) or until it fails (then returns the error).

func NewStub

func NewStub(name string) Role

NewStub returns a placeholder role that blocks until its context is cancelled. It stands in for roles whose story is not implemented yet.

func Select

func Select(names []string, f Factory) ([]Role, error)

Select expands names ("all" means every role) into roles built by f, deduplicated and in canonical order. Unknown names are an error.

type Supervisor

type Supervisor struct {
	// Roles to run.
	Roles []Role
	// Listen is the host:port of the health server. Ignored when Listener is set.
	Listen string
	// Listener, if set, is used instead of listening on Listen.
	Listener net.Listener
	// Ready gates /readyz. Nil means always ready.
	Ready ReadyChecker
	// DrainTimeout bounds shutdown; zero means DefaultDrainTimeout.
	DrainTimeout time.Duration
	// WriteTimeout is the HTTP server's write timeout; zero means
	// DefaultWriteTimeout. A long-lived response (the event stream) moves its
	// own deadline.
	WriteTimeout time.Duration
	// Logger; nil means slog.Default().
	Logger *slog.Logger
}

Supervisor runs roles and the health server together.

func (*Supervisor) Run

func (s *Supervisor) Run(ctx context.Context) error

Run starts every role and the health server and blocks until ctx is cancelled or a role stops. A cancelled ctx is a clean shutdown and returns nil if the roles stopped within the drain timeout. A role that returns while the supervisor is still running, or fails, cancels the others and makes Run return an error.

Jump to

Keyboard shortcuts

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