Documentation
¶
Overview ¶
Package budget answers one question for unattended pools: may we spend more agent money right now? Every enqueued agent task is a real cost, so the guard projects spend from the journal's task.enqueued facts and can defer to an operator-supplied command for custom ceilings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FactSource ¶
type FactSource interface {
Facts(ctx context.Context, after int64, limit int) ([]journal.Fact, error)
CountFacts(ctx context.Context, ftype journal.FactType, since time.Time) (int64, error)
}
FactSource is the journal view the guard projects spend from. *queue.Queue satisfies it: the count is a SQL pushdown, not a journal scan.
type Guard ¶
type Guard struct {
// DailyCap is the maximum number of enqueued agent tasks per calendar
// day (local midnight). 0 = unlimited.
DailyCap int
// BudgetCmd, when set, is the final authority: it runs before every
// harvest tick; exit 0 means within budget, any non-zero exit skips
// the tick (its output becomes the log reason). Allows operators to
// plug real cost accounting in.
BudgetCmd string
// Now is overridable in tests.
Now func() time.Time
}
Guard gates how much agent work a pool may start. Zero-value Guard allows everything.
func (Guard) Check ¶
Check reports whether the pool may enqueue more work, and if not, a human-readable reason for the log.
func (Guard) SpentToday ¶
func (g Guard) SpentToday(ctx context.Context, src FactSource) int
SpentToday counts today's enqueued tasks from the journal. Every enqueue is presumed to become one agent run: on an agent-pool database this is exact; manually enqueued sh/http tasks count too (conservative).