Documentation
¶
Overview ¶
Package watch hosts runtime condition observers (spec §4.2).
Index ¶
- func DockerAvailable() error
- func MapDockerEvent(line []byte) (string, map[string]string)
- func MapDockerInspect(out string) string
- func RunDockerWatch(ctx context.Context, cfg Config, container string, emit Emitter) error
- func RunFileWatch(ctx context.Context, cfg Config, path string, emit Emitter) error
- func RunGitWatch(ctx context.Context, cfg Config, repo string, emit Emitter) error
- func RunPoller(ctx context.Context, cfg Config, posType, negType, source string, probe Prober, ...)
- func ValidateType(t string) error
- type Config
- type Emitter
- type Manager
- type Prober
- type Watch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DockerAvailable ¶
func DockerAvailable() error
DockerAvailable reports whether the docker CLI is usable; watch creation refuses docker watches without it.
func MapDockerEvent ¶
MapDockerEvent maps one `docker events --format '{{json .}}'` line to a RuntimePulse event type; "" means ignore the line.
func MapDockerInspect ¶
MapDockerInspect maps `docker inspect --format '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}'` output to an event type for the initial check; "" means unknown.
func RunDockerWatch ¶
RunDockerWatch performs the initial check via `docker inspect`, then streams `docker events` for the container, mapping lines to events. If the subprocess exits (docker daemon restart, …) it re-inspects (catching transitions missed in the gap) and restarts the stream after a backoff. Requires the docker CLI on PATH (validated at watch creation). Blocks until ctx is cancelled.
func RunFileWatch ¶
RunFileWatch watches a single file path via its parent directory (so creation is observable) and emits file.created/changed/removed. Initial check: an existing file emits file.created immediately. Debounce is TRAILING-EDGE: fs events reset a timer; when the burst goes quiet for the debounce window (Config.StabilityThreshold, default 500ms), one event is emitted reflecting the file's final state — so rm+recreate bursts report the truth (file.changed), never a stale file.removed. Blocks until ctx is cancelled.
func RunGitWatch ¶
RunGitWatch watches a repository's .git/HEAD (branch switches → git.branch.changed, payload branch) and .git/refs/heads + packed-refs (ref updates → git.ref.changed). There is no initial event: git watching is pure edge (no boolean state). A push is not reliably detectable locally, hence no git.pushed (spec note, §4.1). Blocks until ctx is cancelled.
func RunPoller ¶
func RunPoller(ctx context.Context, cfg Config, posType, negType, source string, probe Prober, emit Emitter)
RunPoller implements the spec's triggering semantics (§4.2) for polling watch types: the current state is emitted immediately on start (initial check), afterwards only state transitions emit, and a transition must hold for StabilityThreshold before it is believed (flap suppression). Blocks until ctx is cancelled.
func ValidateType ¶
Types ¶
type Config ¶
type Config struct {
Interval time.Duration `json:"interval,omitempty"`
StabilityThreshold time.Duration `json:"stabilityThreshold,omitempty"`
}
Config controls polling cadence and flap suppression. Durations marshal as nanoseconds in JSON (stored in the watches table).
func (Config) WithDefaults ¶
WithDefaults fills zero values; a zero threshold means transitions emit immediately (no debounce).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns one goroutine per active watch inside the daemon.
func NewManager ¶
func (*Manager) Run ¶
Run records the lifetime ctx and arms all persisted watches (daemon boot re-arm). Must be called once before Start.
func (*Manager) RunningIDs ¶
RunningIDs returns the ids of currently running watchers, sorted.
type Prober ¶
Prober reports whether the watched condition currently holds.
func HTTPProber ¶
HTTPProber: available = the target ITSELF answers with a 2xx/3xx status. Redirects are not followed — an app that 302s "/" → "/login" is up; the redirect target's health is not this watch's business.
func ProcessProber ¶
ProcessProber: running = some process's full command line contains pattern as a case-sensitive substring. Implemented with gopsutil on every platform (owner decision, windows-support spec §2) — identical semantics on macOS/Linux/Windows, no pgrep dependency. The prober's own process (the daemon) is excluded; as with pgrep before it, a pattern matching another runtimepulse invocation's argv will match.