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 ¶
Types ¶
type BudgetExhaustion ¶
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.