items

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 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 items is the items ledger: the only writer of a unit's items.

Index

Constants

View Source
const (
	OutcomeApplied  = "applied"
	OutcomeNoop     = "noop"
	OutcomeProposed = "proposed"
	OutcomeRefused  = "refused"
)

Outcomes of an op in the log.

View Source
const ExtractedLinkLookback = 7 * 24 * time.Hour

ExtractedLinkLookback is how far before its item's creation an extracted link may start: the extractor's window holds older messages, as far back as the Slack backfill.

Variables

View Source
var ErrNoProposal = errors.New("no such proposal")

ErrNoProposal is Decide's error for an id that names no proposal.

Functions

func DedupeKey

func DedupeKey(o items.Op) string

DedupeKey is the identity of a proposal among the open ones: its op without anchor, reason, basis and evidence.

Types

type Applied

type Applied struct {
	Op      items.Op   `json:"op"`
	Item    items.Item `json:"item"`
	Changed bool       `json:"changed"`
}

type Applier

type Applier interface {
	Apply(ctx context.Context, prov items.Provenance, ops []items.Op) (Result, error)
	Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
}

type Commit

type Commit struct {
	Items     []items.Item
	Log       []LogEntry
	Proposals []Proposal
	// Decided are the proposals a decision this commit applies was made on, at DecidedAt.
	Decided   []int64
	DecidedAt time.Time
}

type DisabledError

type DisabledError struct{ Provider unit.ProviderID }

DisabledError is returned, with nothing applied, when an op or a proposal is on a unit of a disabled plugin; the daemon answers it with 409. A link to such a unit is stored.

func (*DisabledError) Error

func (e *DisabledError) Error() string

type Ledger

type Ledger struct {
	Store   Store
	Links   port.LinkStore             // nil refuses link ops
	Enabled func(unit.ProviderID) bool // nil: every provider enabled
	Clock   port.Clock
	Log     func(string, ...any)
	// contains filtered or unexported fields
}

Ledger serializes Apply, Reconcile and Decide; a process keeps one Ledger per store.

func (*Ledger) Apply

func (l *Ledger) Apply(ctx context.Context, prov items.Provenance, ops []items.Op) (Result, error)

Apply applies ops in order, each applied, proposed, refused or a no-op, and commits the outcome of the batch at once.

func (*Ledger) Decide

func (l *Ledger) Decide(ctx context.Context, id int64, accept bool) (Result, error)

Decide applies proposal id's decision, which its gate holds: accept applies its Op as user, a rejection changes nothing. A decision applies once: deciding a proposal a decision was applied to changes nothing, as when a gate's consequence runs again after a crash. An accepted Op the ledger refuses leaves the proposal undecided. ErrNoProposal is an id no proposal has.

func (*Ledger) Items

func (l *Ledger) Items(ctx context.Context, u unit.Unit) ([]items.Item, error)

func (*Ledger) Load added in v0.4.0

func (l *Ledger) Load(ctx context.Context, units []unit.Unit) (map[unit.Unit][]items.Item, error)

Load are the items of units; a unit with none is absent.

func (*Ledger) Proposals

func (l *Ledger) Proposals(ctx context.Context, state ProposalState) ([]Proposal, error)

func (*Ledger) Query

func (l *Ledger) Query(ctx context.Context, q Query) ([]items.Item, error)

func (*Ledger) Reconcile

func (l *Ledger) Reconcile(ctx context.Context, u unit.Unit, desired []items.Item, at unit.Anchor, absent items.Resolution) (Result, error)

Reconcile makes the derived items of u equal desired: create or update each, and resolve an open derived item absent from desired with Resolution absent (superseded when "") and evidence {unit_event, at}. Desired items carry their final State and Resolution. A derived change to a confirmed item is logged noop with reason "confirmed" and never proposed. Reconcile on a disabled provider returns DisabledError and writes nothing.

func (*Ledger) SetLinked added in v0.4.0

func (l *Ledger) SetLinked(f func(ctx context.Context, ls []link.Link) error)

SetLinked makes the ledger tell f the links each Apply stored, once it committed; f runs under the ledger's lock, so it must not call the ledger, and its error is logged. nil tells nothing then.

func (*Ledger) SetSettle added in v0.4.0

func (l *Ledger) SetSettle(f Settler)

SetSettle makes the ledger settle an item once a batch stored its links; nil settles nothing then.

type LogEntry

type LogEntry struct {
	Unit       unit.Unit
	Item       string
	Op         items.Op
	Provenance items.Provenance
	Outcome    string // applied, noop, proposed, refused
	Reason     string
	At         time.Time
}

type Proposal

type Proposal struct {
	ID         int64            `json:"id"`
	Unit       unit.Unit        `json:"unit"`
	Item       string           `json:"item"`
	Op         items.Op         `json:"op"`
	Provenance items.Provenance `json:"provenance"`
	Reason     string           `json:"reason"`
	State      ProposalState    `json:"state"`
	At         time.Time        `json:"at"`
	// Decided says a decision of it was applied.
	Decided bool `json:"decided,omitempty"`
}

type ProposalState

type ProposalState string // "open", "accepted", "rejected"

ProposalState is where a proposal stands, as its gate says: open until a person decides it.

const (
	ProposalOpen     ProposalState = "open"
	ProposalAccepted ProposalState = "accepted"
	ProposalRejected ProposalState = "rejected"
)

type Query

type Query struct {
	Units     []unit.Unit
	State     items.State
	Providers []unit.ProviderID
}

type Reader

type Reader interface {
	Load(ctx context.Context, units []unit.Unit) (map[unit.Unit][]items.Item, error)
	Query(ctx context.Context, q Query) ([]items.Item, error)
	Proposals(ctx context.Context, state ProposalState) ([]Proposal, error)
	Log(ctx context.Context, u unit.Unit, since time.Time) ([]LogEntry, error) // op outcomes, for history
}

Reader is the read half of Store.

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context, u unit.Unit, desired []items.Item, at unit.Anchor, absent items.Resolution) (Result, error)
}

type Refused

type Refused struct {
	Index  int      `json:"index"` // position in the ops passed
	Op     items.Op `json:"op"`
	Reason string   `json:"reason"`
}

type Result

type Result struct {
	Applied  []Applied  `json:"applied"`
	Proposed []Proposal `json:"proposed"`
	Refused  []Refused  `json:"refused"`
}

type Settler added in v0.4.0

type Settler func(ctx context.Context, ls []link.Link, it items.Item) (op items.Op, ok bool, err error)

Settler is the op that settles open item it through its links ls from what their targets already show, such as pull requests merged after the ask; ok is false when nothing settles it yet.

type Store

type Store interface {
	Reader
	Commit(ctx context.Context, c Commit) error // items, op log, new proposals in one transaction; notes TopicItems when anything but log rows changed
}

Jump to

Keyboard shortcuts

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