fleet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

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

View Source
const LostAfter = 30 * time.Second

LostAfter is how long a running node may stay silent before it counts as lost (three missed heartbeats).

Variables

View Source
var HeartbeatEvery = 10 * time.Second

HeartbeatEvery is how often a node reports in; it counts as lost after LostAfter without one.

View Source
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 Count

func Count(ctx context.Context, q db.DBTX, f Filter) (int64, error)

Count is how many nodes match f.

func Drain

func Drain(ctx context.Context, q db.DBTX, id string) (bool, error)

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

func Reap(ctx context.Context, pool *pgxpool.Pool) (int, error)

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

func Remove(ctx context.Context, q db.DBTX, id string) (removed, exists bool, err error)

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.

func Status

func Status(n Node, now time.Time) string

Status is online, draining, stopped or lost.

func Workers

func Workers(w *river.Workers, d *core.Deps)

Types

type Filter

type Filter struct {
	Pattern    string
	State      string
	Stale      bool
	Queues     []string
	EncodeOnly bool
}

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

type Node = db.Node

Node is one machine's row: what it is, what it works on, and how it was doing at its last report.

func All

func All(ctx context.Context, q db.DBTX) ([]Node, error)

All is every node, running ones first.

func Page

func Page(ctx context.Context, q db.DBTX, f Filter, afterAt pgtype.Timestamptz, afterID string, limit int32) ([]Node, error)

Page is up to limit nodes matching f, newest start first, after the (afterAt, afterID) node when afterAt is set.

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

func (ReapArgs) Kind

func (ReapArgs) Kind() string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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