Documentation
¶
Overview ¶
Package pipeline wires the six independent budgetclaw data-flow packages (parser, pricing, db, budget, enforcer, ntfy) into one Handler function suitable for the watcher.
The pipeline is deliberately linear and single-function so the order of operations is obvious to readers:
- Compute cost for the event (pricing)
- Write the event + rollup delta to SQLite (db)
- Check existing breach lock for (project, branch): - If locked and expired → auto-release, proceed. - If locked and active → re-kill, return (no further eval). - If not locked → continue.
- Evaluate every matching budget rule for this event
- For each breached rule, dispatch the action: - warn → SendWarn via ntfy - kill → HandleBreach (write lockfile + SIGTERM) and SendKill
Errors from downstream packages are logged via the package logger but do NOT abort the Handler. The watcher keeps running even when one event fails; a transient db hiccup must never silently stop all budget enforcement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pipeline ¶
type Pipeline struct {
Config *budget.Config
DB *db.DB
Enforcer *enforcer.Enforcer
Notifier *ntfy.Client
// Now is the clock used for lock expiry and period bounds.
// Tests inject a fixed time.
Now func() time.Time
// Logger receives structured debug and error messages. Quiet
// by default so daemon mode does not spam stderr.
Logger *slog.Logger
// contains filtered or unexported fields
}
Pipeline holds the live dependencies of the data-flow core. The watcher wires a Pipeline once at startup and calls Handle for every parsed event.
All fields except Now and Logger are required. Now defaults to time.Now; Logger defaults to a discarding slog handler.
func (*Pipeline) Handle ¶
Handle is the Watcher handler. It takes a parsed event and runs the full pipeline. Returns nil in every non-fatal case — even when internal steps fail — so the watcher keeps running. Context cancellation is propagated: callers that abort ctx will see Handle return ctx.Err from whichever step noticed.
func (*Pipeline) UnknownModels ¶ added in v0.1.2
UnknownModels returns a snapshot of model IDs the pipeline has skipped this run, paired with their event counts. Useful for status output and tests; safe for concurrent callers.