Documentation
¶
Overview ¶
Package items is the items ledger: the only writer of a unit's items.
Index ¶
- Constants
- Variables
- func DedupeKey(o items.Op) string
- type Applied
- type Applier
- type Commit
- type DisabledError
- type Ledger
- func (l *Ledger) Apply(ctx context.Context, prov items.Provenance, ops []items.Op) (Result, error)
- func (l *Ledger) Decide(ctx context.Context, id int64, accept bool) (Result, error)
- func (l *Ledger) Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
- func (l *Ledger) Proposals(ctx context.Context, state ProposalState) ([]Proposal, error)
- func (l *Ledger) Query(ctx context.Context, q Query) ([]items.Item, error)
- func (l *Ledger) Reconcile(ctx context.Context, u unit.Unit, desired []items.Item, at unit.Anchor, ...) (Result, error)
- type LogEntry
- type Proposal
- type ProposalState
- type Query
- type Reader
- type Reconciler
- type Refused
- type Result
- type Store
Constants ¶
const ( OutcomeApplied = "applied" OutcomeNoop = "noop" OutcomeProposed = "proposed" OutcomeRefused = "refused" )
Outcomes of an op in the log.
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 ¶
var ErrNoProposal = errors.New("no such proposal")
ErrNoProposal is Decide's error for an id that names no proposal.
Functions ¶
Types ¶
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 ¶
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 ¶
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) 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.
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 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.