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 ¶
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).
const DefaultWriteTimeout = 10 * time.Second
DefaultWriteTimeout is the HTTP server's write timeout.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Factory ¶
Factory builds the Role for a name. Real roles replace the stubs as their stories land.
type HTTPRole ¶
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 ¶
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 Role ¶
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).
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.