Documentation
¶
Overview ¶
Package agent implements the outbound-only WebSocket worker loop for Home Assistant OS and edge standby nodes.
Index ¶
Constants ¶
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 )
const ( DefaultHAOptionsPath = "/data/options.json" DefaultPauseMs = 3000 DefaultPauseJitterMs = 1500 MinTokenLength = 24 )
Variables ¶
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 ¶
LoadConfig loads `/data/options.json` (when present) and overlays `EDGEFETCH_*` (or `CRAWLER_*`) environment variables.
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.