Documentation
¶
Overview ¶
Package reconcile gives a standalone agent a level-triggered (declarative) way to keep the controller's job view converged with the agent's own authoritative local state.
The fast path stays the per-event delta push (eventoutbox): started -> progress -> completed/failed. But deltas can be lost or arrive out of order, which strands a controller row in a non-terminal state forever (witnessed: a late 'running' delta overwriting a delivered 'completed'). This package is the safety net: on startup and every Interval the agent POSTs its FULL set of non-terminal + recently-finished jobs, and the controller makes its rows for this (site,node) match. It is intentionally low-frequency — correctness, not latency, is its job; the deltas already provide instant UI updates.
Transport reuses the agent's existing pooled, bearer-authed, Traefik-dialing HTTP client, so this is a plain stateless POST: no persistent socket, no router-pod pinning, survives router rollouts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run fires one reconcile immediately (so a just-booted agent converges the controller right after the orphan sweep), then every Interval until ctx is cancelled. Failures are logged and retried on the next tick — a missed reconcile is self-healing by construction (the next full snapshot corrects whatever drifted).
Types ¶
type Config ¶
type Config struct {
Client *http.Client // pooled, bearer + Traefik-dial transport (reuse the outbox client)
URL string // full controller endpoint, e.g. https://…/api/duplicacy/reconcile
Site string // site identifier, e.g. "site-a"
Node string // short host name
Interval time.Duration // default 5m
Snapshot SnapshotFunc // builds the declared job set from the local DB
Logger *slog.Logger // optional; defaults to slog.Default()
}
Config wires the reconcile loop. All fields except Interval are required.
type Snapshot ¶
type Snapshot struct {
Site string `json:"site"`
Node string `json:"node"`
SnapshotAt time.Time `json:"snapshot_at"`
Jobs []jobstore.JobRef `json:"jobs"`
}
Snapshot is the agent's declared job state for one (site,node) at a point in time. SnapshotAt lets the controller skip rows that changed after the agent built the snapshot (avoids racing an in-flight delta for a just-started job).