Documentation
¶
Overview ¶
Package app assembles the modules into the API handler and the worker's River client, with what an application built on ulka-vms adds (Extension).
Index ¶
- Variables
- func CheckEnv(get func(string) string) (errs, warns []string)
- func Handler(pool *pgxpool.Pool, store core.Storage, cfg Config, ext Extension) (http.Handler, error)
- func IsLocal(raw string) bool
- func Main(ext Extension)
- func MustEnv(name string) string
- func MustOneOf(name string, choices []string) string
- func MustSecret(name string, min int) string
- func MustURL(name string) string
- func NewWorkerClient(pool *pgxpool.Pool, store core.Storage, cfg Config, ...) (*river.Client[pgx.Tx], error)
- func ParseEncodeSlots(s string) (int, error)
- func ParseProxies(s string) ([]netip.Prefix, error)
- func ParseQueues(s string, known map[string]river.QueueConfig) (map[string]river.QueueConfig, error)
- func Placeholder(host string) bool
- func RunWorker(ctx context.Context, dsn string, store core.Storage, cfg Config, ...) error
- func Serve(ctx context.Context, dsn, addr string, store core.Storage, cfg Config, ...) error
- func ServeOrigin(ctx context.Context, addr string, store core.Storage, clickHouseURL string, ...) error
- func SetLimits(ctx context.Context, ownerDSN string, extra map[string]any, args []string) error
- func StartEncoder(ctx context.Context, pool *pgxpool.Pool, store core.Storage, cfg Config, ...) <-chan struct{}
- type Config
- type Extension
Constants ¶
This section is empty.
Variables ¶
var Queues = map[string]river.QueueConfig{
"interactive": {MaxWorkers: 4},
"standard": {MaxWorkers: 2},
"webhooks": {MaxWorkers: 20},
"maintenance": {MaxWorkers: 2},
}
Queues is ulka-vms's queues, with a sensible concurrency for tests and a laptop. Real nodes choose their own set with WORKER_QUEUES (ParseQueues), so an encoding box and a webhook box can run different work.
Functions ¶
func CheckEnv ¶
CheckEnv judges the environment of a deployment that is not on this machine (PUBLIC_URL not local) and returns every setting that would make it look healthy while it isn't: development stand-ins, example values and addresses that only exist on this machine. warns are legitimate but worth seeing.
func Handler ¶
func Handler(pool *pgxpool.Pool, store core.Storage, cfg Config, ext Extension) (http.Handler, error)
Handler builds the API over an already-connected pool.
func IsLocal ¶
IsLocal reports whether a URL points at this machine (localhost, 127.0.0.1, *.localhost, *.test).
func Main ¶
func Main(ext Extension)
Main runs the command line: migrate, api, worker, limits, and the extension's own commands.
func MustSecret ¶
MustSecret is a secret of at least min characters.
func MustURL ¶
MustURL is an http(s) address with a host, checked at boot so a typo fails here, not in the first job using it.
func NewWorkerClient ¶
func NewWorkerClient(pool *pgxpool.Pool, store core.Storage, cfg Config, queues map[string]river.QueueConfig, ext Extension) (*river.Client[pgx.Tx], error)
NewWorkerClient registers every module's workers and periodic jobs.
func ParseEncodeSlots ¶
ParseEncodeSlots reads WORKER_ENCODE_SLOTS: how many video pieces this node encodes at once. "auto" is one per transcoder.EncodeThreads cores (never fewer than one), so a bigger machine is given proportionally more; 0 takes none.
func ParseProxies ¶
ParseProxies reads TRUSTED_PROXIES: "none", or comma-separated addresses and ranges.
func ParseQueues ¶
func ParseQueues(s string, known map[string]river.QueueConfig) (map[string]river.QueueConfig, error)
ParseQueues reads "interactive=8,standard=8" into the queues this node works and how many jobs of each at once; "none" is a node that only encodes.
func Placeholder ¶
Placeholder is example.com, .org or .net and anything under them.
func RunWorker ¶
func RunWorker(ctx context.Context, dsn string, store core.Storage, cfg Config, queues map[string]river.QueueConfig, encodeSlots int, ext Extension) error
RunWorker runs River workers until ctx is cancelled (or the extension's ServeNode returns).
func Serve ¶
func Serve(ctx context.Context, dsn, addr string, store core.Storage, cfg Config, ext Extension) error
Serve connects, then answers HTTP on addr until ctx is cancelled.
func ServeOrigin ¶
func ServeOrigin(ctx context.Context, addr string, store core.Storage, clickHouseURL string, trusted []netip.Prefix) error
ServeOrigin serves videos' segments from storage on addr until ctx ends; each response is metered in ClickHouse.
func SetLimits ¶
SetLimits changes one workspace's limits, given as name=value; the others keep what they were. With no changes it only prints them, and with no workspace it lists them all. It connects as the database owner, since no workspace may raise its own.
func StartEncoder ¶
func StartEncoder(ctx context.Context, pool *pgxpool.Pool, store core.Storage, cfg Config, rc *river.Client[pgx.Tx], slots int) <-chan struct{}
StartEncoder starts this node's side of the scheduler beside its River client; stop it by cancelling ctx, then wait on the returned channel for the pieces already running.
Types ¶
type Config ¶
type Config struct {
PublicURL string // where the API and the customer console are reached
AdminURL string // where the application's admins work, if it has any
OriginURL string // where video segments are
PlayerURL string // where viewers watch and stream
DocsURL string // where the guides and the API reference are read
PlayerDemo string // library/video the player host's home shows; empty for none
SignupOpen bool // whether anyone may create a workspace (SIGNUP)
ClickHouseURL string // where delivery logs and usage rollups are
// Reverse proxies in front of the API, whose X-Forwarded-For names the caller (API key IP allow lists).
TrustedProxies []netip.Prefix
Geo *core.Geo
SealKey []byte // SEAL_KEY, 32 bytes
Keys core.KeyStore // a key service; nil keeps keys sealed in the database
}
Config is what the modules need beyond the database and storage.
type Extension ¶
type Extension struct {
Name string // the command's name, in its usage line and as its migrations' prefix
Migrations fs.FS // its schema, applied after ulka-vms's
// Configure reads its settings into cfg at start, exiting on a bad one as ulka-vms does with its own.
Configure func(cfg *Config)
// CheckEnv finds its settings that would make a public deployment look healthy while it isn't (see CheckEnv).
CheckEnv func(get func(string) string) (errs, warns []string)
Commands map[string]func(ctx context.Context) error // more subcommands beside migrate, api and worker
// Routes adds its API; the returned function, if any, wraps the whole handler.
Routes func(mux *http.ServeMux, d *core.Deps) (wrap func(http.Handler) http.Handler, err error)
Video func(d *core.Deps) video.Options // what it adds to video
Workers func(w *river.Workers, d *core.Deps)
Jobs []*river.PeriodicJob
Queues map[string]river.QueueConfig // its own queues, beside ulka-vms's
// OpenAPI is the application's whole API description (Ulka VMS's routes and its own), served at
// /v1/openapi.json in place of Ulka VMS's.
OpenAPI []byte
// ServeNode runs the worker's River client until ctx ends (registering the machine, say); nil just runs it.
ServeNode func(ctx context.Context, pool *pgxpool.Pool, client *river.Client[pgx.Tx], queues map[string]river.QueueConfig, jobs bool) error
}
Extension is what an application built on ulka-vms adds: its settings, modules, jobs and schema. The zero value is ulka-vms on its own.