pace

package
v1.0.0-rc.5 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pace decides whether a session may start on a subscription now.

A subscription is a provider account. Its use comes from the newest reading a runner took through the provider's CLI, plus the headroom reserved for sessions started since that reading. A session starts only while:

  • the reading is no older than the subscription's stale age;
  • its weekly use is at or below even pace, the elapsed share of the week (50% halfway through). Work that finishes something already started may run ahead of even pace by the subscription's headroom;
  • its short window, such as the five-hour one, is below its stop threshold.

Check is a pure function: the caller passes the clock.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRules = Rules{
	WeekLength:        7 * 24 * time.Hour,
	ShortWindowStop:   90,
	Headroom:          10,
	StaleAfter:        30 * time.Minute,
	ReservePerSession: v1alpha1.Usage{Weekly: 1, ShortWindow: 5},
}

DefaultRules are the rules for a subscription that sets none.

Functions

This section is empty.

Types

type Rules

type Rules struct {
	// WeekLength is the length of the weekly window.
	WeekLength time.Duration
	// ShortWindowStop is the short window's use, in percent, at which no
	// session starts.
	ShortWindowStop float64
	// Headroom is how far, in percent of the week, work that finishes
	// something already started may run ahead of even pace.
	Headroom float64
	// StaleAfter is the age at which a reading counts as no room.
	StaleAfter time.Duration
	// ReservePerSession is the headroom held for a session between its start
	// and the next reading.
	ReservePerSession v1alpha1.Usage
}

Rules are a subscription's pace rules.

func RulesFor

func RulesFor(spec v1alpha1.SubscriptionSpec, defaults Rules) Rules

RulesFor returns a subscription's rules: its own where it sets them, and defaults for the rest.

type Verdict

type Verdict struct {
	// Fits is true when a session may start.
	Fits bool
	// Reason says, when it doesn't fit, why, with its numbers.
	Reason string
	// Behind is how far, in percent of the week, the subscription's use is
	// behind even pace. Among the subscriptions that fit, the one furthest
	// behind goes first. It is 0 for an unpaced subscription.
	Behind float64
	// Unpaced is true for a subscription without a weekly budget.
	Unpaced bool
}

Verdict is whether a session may start on a subscription.

func Check

func Check(sub *v1alpha1.Subscription, rules Rules, reserved []v1alpha1.Reservation, finishesWork bool, now time.Time) Verdict

Check decides whether a session may start on sub at now. reserved are the reservations held on sub by sessions that started or were offered; those older than the reading are included in it and don't count again. finishesWork is true for incident, repair and continuing tasks.

Jump to

Keyboard shortcuts

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