plan

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 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 plan is the engine's commands and reads on a pursuit's plan and its progress: each revision kept with its reason, which change a session works on, tokens spent added and checked against the appetite in the same transaction, the circuit breaker, and the Needs you items they raise; each change one command with its event.

Index

Constants

View Source
const By = "circuit breaker"

By is who stops a pursuit when its spend reaches its appetite.

Variables

View Source
var (
	ErrPlanInvalid   = errors.New("plan invalid")
	ErrNoPlan        = errors.New("no plan")
	ErrNoReason      = errors.New("no reason")
	ErrUnknownChange = errors.New("unknown change")
	ErrNoSession     = errors.New("no session")
	ErrBadTokens     = errors.New("bad tokens")
)

The kinds of Refusal this package adds to work's. Each is a *work.Refusal, so the API replies bad_request with its message.

Functions

func Current

func Current(db *sql.DB, session string) (slug, change string, err error)

Current returns the pursuit and planned change the session works on, read from db, a store opened read-only (store.OpenReadOnly). It never writes. No such session, or a store from before plans had changes, gives empty names and no error.

func Land

func Land(ctx context.Context, s work.Submitter, slug string, landed map[string]progress.Landing) error

Land records each planned open change named in landed as landed, with event change.landed, then sets an active pursuit done, with event pursuit.done, once every change in its plan has landed. Repeating it changes nothing.

func Work

func Work(ctx context.Context, s work.Submitter, in WorkIn) error

Work records that in.Session works on the pursuit's planned change, replacing the change it worked on before, with event change.in_work. The pursuit must be active and the change planned in its current revision.

Types

type ChangeSpend

type ChangeSpend struct {
	Change string
	Tokens int64
}

ChangeSpend is the tokens spent on one change; an empty Change is the pursuit itself.

type Detail

type Detail struct {
	Pursuit        string
	N, Replans     int
	Reason, Person string
	At             time.Time
	Changes        []plan.Change
	History        []Revision
}

Detail is a pursuit's current plan: its revision number, who wrote it, when and why, its changes, and how many times it was replanned. History holds every revision, oldest first, when asked for.

func Set

func Set(ctx context.Context, s work.Submitter, in SetIn) (Detail, error)

Set stores in.Plan, already checked by internal/plan, as the pursuit's next revision with event plan.revised. Only an active pursuit takes a plan; a revision after the first needs a reason. The current plan's changes are rows; one a revision drops stays, no longer planned, with its spend.

func Show

func Show(ctx context.Context, s work.Submitter, slug string, history bool) (Detail, error)

Show returns the pursuit's current plan, and every revision when history is asked for. A pursuit with no plan yet is refused, saying how to set one.

type Facts

type Facts struct {
	Planned         []string
	Landed          []LandedChange
	InWork          []string
	AsksOpen        int
	Spent, Appetite int64
	Replans         int
	PerChange       []ChangeSpend
	Needs           []Need
}

Facts is a pursuit's progress, as facts and never one number: the changes planned, landed and in work, asks open, tokens spent against the appetite, replans, spend per change (largest first) and its open Needs you items (newest first).

func Progress

func Progress(ctx context.Context, s work.Submitter, slug string) (Facts, error)

Progress returns the pursuit's progress as facts. A pursuit with no plan has no planned changes and no replans. There are no asks yet, so none are open.

type LandedChange

type LandedChange struct {
	Change, Commit string
	At             time.Time
}

LandedChange is a planned change that has landed on the default branch.

type Need

type Need struct {
	Kind, Text string
	At         time.Time
}

Need is an open Needs you item about a pursuit.

type Revision

type Revision struct {
	N              int
	Reason, Person string
	At             time.Time
	Changes        []string
}

Revision is one stored revision of a plan and the names of its changes.

type SetIn

type SetIn struct {
	Pursuit, Reason, Person string
	Plan                    plan.Plan
}

SetIn stores Plan as the pursuit's next revision. Reason may be empty only for the first.

type SpendIn

type SpendIn struct {
	Pursuit, Change, Session string
	Tokens                   int64
}

SpendIn reports a session's tokens on a pursuit and one of its changes (an empty Change is the pursuit itself). Tokens is the session's running total there, not an increase, so a report repeated or arriving late changes nothing.

type SpendOut

type SpendOut struct {
	Spent, Appetite int64
	State           string
	Warned, Broke   bool
}

SpendOut is the pursuit's spend after the report. Warned and Broke are true only when this report raised the appetite's notice or the circuit breaker.

func Spend

func Spend(ctx context.Context, s work.Submitter, in SpendIn) (SpendOut, error)

Spend adds the increase over the session's held total to the pursuit and the change, with event spend.reported, and checks the appetite in the same transaction. On an active pursuit: the first time spend reaches 80% of the appetite the pursuit's person gets an appetite Needs you item (appetite.warned); when it reaches the appetite the circuit breaker stops the pursuit with its reason and a breaker item (pursuit.stopped), and the idea may be pursued again. A pursuit with no appetite has no notice and no circuit breaker; its spend, like spend on a done or stopped pursuit, is still recorded. No appetite is raised.

type WorkIn

type WorkIn struct {
	Session, Pursuit, Change string
}

WorkIn records that Session works on the pursuit's planned change.

Jump to

Keyboard shortcuts

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