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 ¶
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.
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.