supervisor

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 12 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 keeps every configured camera stream running, one goroutine per stream, restarting it with backoff when it fails.

A camera's main, sub and extern streams are independent Baichuan connections, so they run on separate goroutines rather than being serialised behind one lock per camera; a stall on one must never delay the others.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRunning = errors.New("supervisor: already running")

ErrAlreadyRunning is returned by a second call to Run on the same Supervisor. Two concurrent Run calls would spawn two goroutines per entry, which is exactly the two-connections-to-one-stream overlap this package exists to prevent, so a second call is refused rather than silently duplicating the fleet.

View Source
var ErrNotRunning = errors.New("supervisor: not running")

ErrNotRunning is returned by Reload before Run has started. There is no context to start a stream under yet, and silently deferring the change until Run would make a reload that appeared to succeed do nothing.

View Source
var ErrShuttingDown = errors.New("supervisor: shutting down")

ErrShuttingDown is returned by Reload once Run's context has been cancelled. Run's final wait (see Run) only waits for entries still in the map at the moment it checks; a Reload allowed to start after ctx is already done could still be mid-diff or mid-stop when Run returns and the process exits out from under it, which is exactly what leaves a stream-stop message unwaited. Refusing outright, rather than racing it to completion, closes that window for any Reload that has not already begun; see Run's own reloadMu wait for the one that has.

Functions

This section is empty.

Types

type ReloadResult

type ReloadResult struct {
	Added     int
	Removed   int
	Restarted int
	Unchanged int
}

ReloadResult reports what a Reload did, for the operator page to show and for a test to assert on.

type Runner

type Runner func(ctx context.Context, cfg stream.Config, h *hub.Hub) error

Runner runs one camera stream until ctx is cancelled or it fails. It is a parameter rather than a hard call to stream.Run so the supervisor can be tested without a camera.

type StreamStat

type StreamStat struct {
	Camera      string
	Stream      string
	Running     bool
	LastError   string
	LastErrorAt time.Time
	Restarts    int
}

StreamStat reports one stream's current state for status endpoints.

LastError is never cleared; LastErrorAt says when it happened.

type Supervisor

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

Supervisor runs every stream from a camera list and restarts failed ones.

func New

func New(cams []config.Camera, run Runner) *Supervisor

New builds a Supervisor for cams, using run to drive each stream. Nothing starts until Run is called.

func (*Supervisor) AttachSinks

func (s *Supervisor) AttachSinks(sinkFor func(camera, stream string) stream.FrameSink)

AttachSinks gives every stream named in a camera's rtsp list a frame sink, built by sinkFor.

It takes a factory rather than an RTSP server so this package does not depend on that one: the supervisor's job is running camera connections, and which outputs consume them is not its concern. A camera with no rtsp entry keeps a nil sink, which is the state the HTTP path has always run in.

Call before Run. It panics afterwards rather than racing a live fleet, matching setBackoff.

func (*Supervisor) CameraConfig added in v0.1.9

func (s *Supervisor) CameraConfig(name string) (stream.Config, bool)

CameraConfig returns the connection details the supervisor currently holds for camera name, reflecting any Reload since startup.

func (*Supervisor) Hub

func (s *Supervisor) Hub(name string) (*hub.Hub, bool)

Hub returns one stream's hub by its "<camera>/<stream>" key. Locked because Reload adds and removes entries while the HTTP server is serving.

func (*Supervisor) HubNames

func (s *Supervisor) HubNames() []string

HubNames lists every stream currently configured.

func (*Supervisor) Reload

func (s *Supervisor) Reload(cams []config.Camera) (ReloadResult, error)

Reload brings the running fleet in line with cams, touching only what changed. A stream whose camera is unchanged keeps its connection, its hub and its subscribers: adding a ninth camera must not interrupt the other eight, which is the entire reason this exists rather than a process restart.

A stream that is being replaced is stopped to completion before its replacement starts. Overlapping them gets the replacement a session the camera refuses, because the old one has not been released yet.

func (*Supervisor) Run

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

Run starts one goroutine per configured stream and blocks until ctx is cancelled and every one of them has finished closing.

Run may only be called once. A second concurrent call would spawn a second goroutine per entry, which is a second connection to every stream this Supervisor owns, the exact fault this package exists to prevent, so it returns ErrAlreadyRunning instead.

func (*Supervisor) Stats

func (s *Supervisor) Stats() []StreamStat

Stats returns a snapshot of every stream's current state.

func (*Supervisor) Validate

func (s *Supervisor) Validate(cams []config.Camera) error

Validate reports whether cams would be accepted by Reload, without applying anything or requiring Run to have started.

This exists so a caller writing a config file to disk, such as the control page's config editor, can check it against the running fleet's own constraints BEFORE the write, not just against config.Config's context-free rules. The two disagree in one real case: an [rtsp] section added to a daemon that booted without one passes config.Load (the file is self-consistent) but fails this exact check, because RTSP was never wired up on this Supervisor and cfg.RTSP stays nil here regardless of what the file says. Catching that before the file is written, rather than after, is what stops "saved, but not applied" from leaving a config on disk that the daemon's next restart cannot even boot from.

Jump to

Keyboard shortcuts

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