pipeline

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 12 Imported by: 0

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:

  1. Compute cost for the event (pricing)
  2. Write the event + rollup delta to SQLite (db)
  3. 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.
  4. Evaluate every matching budget rule for this event
  5. 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

func (p *Pipeline) Handle(ctx context.Context, e *parser.Event, _ string) error

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

func (p *Pipeline) UnknownModels() map[string]int

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.

Jump to

Keyboard shortcuts

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