Documentation
¶
Overview ¶
Package fleet is the machines that run workers and encoders: each registers and reports while it runs (Serve), can be drained and removed, and jobs held by one that went silent are put back in the queue (Reap).
Index ¶
- Constants
- Variables
- func Count(ctx context.Context, q db.DBTX, f Filter) (int64, error)
- func Drain(ctx context.Context, q db.DBTX, id string) (bool, error)
- func PeriodicJobs() []*river.PeriodicJob
- func Reap(ctx context.Context, pool *pgxpool.Pool) (int, error)
- func Remove(ctx context.Context, q db.DBTX, id string) (removed, exists bool, err error)
- func Serve(ctx context.Context, pool *pgxpool.Pool, client *river.Client[pgx.Tx], ...) error
- func Status(n Node, now time.Time) string
- func Workers(w *river.Workers, d *core.Deps)
- type Filter
- type Node
- type ReapArgs
- type RetentionArgs
Constants ¶
const LostAfter = 30 * time.Second
LostAfter is how long a running node may stay silent before it counts as lost (three missed heartbeats).
Variables ¶
var HeartbeatEvery = 10 * time.Second
HeartbeatEvery is how often a node reports in; it counts as lost after LostAfter without one.
var Version string
Version is the release this program was built as, set at build time (-ldflags -X); empty, it is read from git.
Functions ¶
func Drain ¶
Drain asks a running node to finish its jobs and stop; false when no running node has that id.
func PeriodicJobs ¶
func PeriodicJobs() []*river.PeriodicJob
func Reap ¶
Reap returns running jobs to the queue when their worker is gone: its node stopped, has not reported for 45 seconds, or never registered. Jobs younger than a minute are left alone so a worker that has just started is never robbed. River would rescue these itself, but only after its 5-hour window; heartbeats let us know within a minute.
func Remove ¶
Remove forgets a node that stopped or went silent. removed is false when it is still running (exists true; drain it first) or there is none (exists false).
func Serve ¶
func Serve(ctx context.Context, pool *pgxpool.Pool, client *river.Client[pgx.Tx], queues map[string]river.QueueConfig, jobs bool) error
Serve registers this worker in the nodes table, starts it, keeps the row current, and drains it when someone asks: no new jobs, running ones finish, then it returns. It also returns, stopping the client, when ctx ends. Registering before starting matters: the reaper treats a job on an unregistered worker as orphaned. jobs is false for a node that only encodes: it registers and reports, but runs no River jobs.
Types ¶
type Filter ¶
Filter narrows Page and Count. Pattern is an ILIKE pattern over host name and id; State one of Status's words or ""; Stale keeps running nodes older than the newest running one's version; Queues keeps nodes working any of them, and EncodeOnly also those that only encode.
type Node ¶
Node is one machine's row: what it is, what it works on, and how it was doing at its last report.
type ReapArgs ¶
type ReapArgs struct{}
ReapArgs puts running jobs back in the queue when the worker holding them has stopped reporting.
func (ReapArgs) InsertOpts ¶
func (ReapArgs) InsertOpts() river.InsertOpts
type RetentionArgs ¶
type RetentionArgs struct{}
RetentionArgs forgets machines a week after they stopped or went silent, daily.
func (RetentionArgs) InsertOpts ¶
func (RetentionArgs) InsertOpts() river.InsertOpts
func (RetentionArgs) Kind ¶
func (RetentionArgs) Kind() string