runbudget

package
v0.4.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package runbudget resolves the optional run-level cost and wall-clock budget from flags and environment and tracks spend against it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBounded

func IsBounded(budget RunBudget) bool

IsBounded reports whether either property is present.

Types

type BudgetExhaustion

type BudgetExhaustion struct {
	Yes    bool    `json:"yes"`
	Reason *string `json:"reason,omitempty"`
}

BudgetExhaustion is the result of a tracker check.

type BudgetTracker

type BudgetTracker struct {
	Budget RunBudget
	// contains filtered or unexported fields
}

BudgetTracker is the mutable accumulator returned by MakeBudgetTracker.

func MakeBudgetTracker

func MakeBudgetTracker(budget RunBudget, startTS float64, priorCostUSD ...float64) *BudgetTracker

MakeBudgetTracker creates a tracker. The optional prior cost defaults to 0.

func (*BudgetTracker) AddCost

func (t *BudgetTracker) AddCost(usd float64)

AddCost accumulates a positive finite provider-cost delta.

func (*BudgetTracker) CostUSD

func (t *BudgetTracker) CostUSD() float64

CostUSD returns the accumulated provider cost.

func (*BudgetTracker) Exhausted

func (t *BudgetTracker) Exhausted(nowMS ...float64) BudgetExhaustion

Exhausted checks cost first and wall time second. Omit nowMS to use the ambient wall clock.

type RunBudget

type RunBudget struct {
	MaxCostUSD *float64 `json:"maxCostUsd,omitempty"`
	MaxWallMS  *float64 `json:"maxWallMs,omitempty"`
}

RunBudget is an explicitly supplied run-level budget. A nil field means that dimension is unbounded.

func ResolveRunBudget

func ResolveRunBudget(flags *RunBudgetFlags, env map[string]string) RunBudget

ResolveRunBudget applies flag-over-environment precedence. A non-nil env map is used exactly (including an explicitly empty map); nil reads process env.

type RunBudgetFlags

type RunBudgetFlags struct {
	MaxCost  *float64 `json:"maxCost"`
	MaxHours *float64 `json:"maxHours"`
}

RunBudgetFlags mirrors the two CLI flag values.

Jump to

Keyboard shortcuts

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