agent

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 19 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 agent implements the outbound-only WebSocket worker loop for Home Assistant OS and edge standby nodes.

Index

Constants

View Source
const (
	DefaultPingInterval          = 30 * time.Second
	DefaultReadWatchdog          = 50 * time.Second
	DefaultHealthyResetDur       = 30 * time.Second
	DefaultShutdownDrain         = 25 * time.Second
	DefaultUploadTimeout         = 45 * time.Second
	DefaultShutdownUploadTimeout = 10 * time.Second
)
View Source
const (
	DefaultHAOptionsPath = "/data/options.json"
	DefaultPauseMs       = 3000
	DefaultPauseJitterMs = 1500
	MinTokenLength       = 24
)

Variables

View Source
var Version = "1.1.0"

Version is the EdgeFetch binary/add-on release version reported in X-Agent-Version and agent_hello. Overridable at build time via -ldflags="-X github.com/bartrumb/edgefetch/internal/agent.Version=...".

Functions

func Run

func Run(
	ctx context.Context,
	cfg Config,
	crawler *crawl.Crawler,
	allow func(*url.URL) error,
	hubTransport http.RoundTripper,
	log *slog.Logger,
	rtOpts RuntimeOpts,
) error

Run maintains a persistent outbound WebSocket session to `cfg.HubURL/agent/ws`, automatically reconnecting with full-jitter exponential backoff on network drops and draining in-flight work cleanly on `SIGTERM`.

Types

type Config

type Config struct {
	HubURL        string   `json:"hub_url"`
	AgentToken    string   `json:"agent_token"`
	SiteID        string   `json:"site_id"`
	UserAgent     string   `json:"user_agent"`
	PauseMs       int      `json:"pause_ms"`
	PauseJitterMs int      `json:"pause_jitter_ms"`
	AllowedHosts  []string `json:"allowed_hosts"`
}

Config holds validated settings for outbound `agent` mode.

func LoadConfig

func LoadConfig(optionsPath string) (Config, error)

LoadConfig loads `/data/options.json` (when present) and overlays `EDGEFETCH_*` (or `CRAWLER_*`) environment variables.

func LoadConfigFrom

func LoadConfigFrom(optionsPath string, getenv func(string) string) (Config, error)

LoadConfigFrom is the pure, testable configuration loader used by `LoadConfig`.

type RuntimeOpts

type RuntimeOpts struct {
	PingInterval          time.Duration
	ReadWatchdog          time.Duration
	HealthyResetDur       time.Duration
	ShutdownDrain         time.Duration
	UploadTimeout         time.Duration
	ShutdownUploadTimeout time.Duration
	OnConnected           func()
}

RuntimeOpts allows integration tests to shorten keepalive/drain timers without altering production defaults.

Jump to

Keyboard shortcuts

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