Documentation
¶
Overview ¶
Package outbox keeps the drafts the loop proposes and publishes the ones the user, or their approval policy, approved.
Index ¶
- Constants
- Variables
- func EvidenceOps(d draft.Draft) []items.Op
- type AppliedStore
- type Applier
- type Effect
- type EffectApplier
- type EffectLookup
- type Effects
- type Evidence
- type Facts
- type Filter
- type Implementer
- type ItemReader
- type Manifests
- type Policies
- type Proposal
- type Resolver
- type Service
- func (s *Service) ApplyPending(ctx context.Context) error
- func (s *Service) Approve(ctx context.Context, id draft.ID, text *string) (draft.Draft, error)
- func (s *Service) Discard(ctx context.Context, id draft.ID, reason string) (draft.Draft, error)
- func (s *Service) Edit(ctx context.Context, id draft.ID, text string) (draft.Draft, error)
- func (s *Service) List(ctx context.Context, f Filter) ([]draft.Draft, error)
- func (s *Service) NextDeadline(ctx context.Context) (time.Time, bool, error)
- func (s *Service) Propose(ctx context.Context, p Proposal) (draft.Draft, error)
- func (s *Service) RecordSent(ctx context.Context, p Proposal, ev draft.Evidence) (draft.Draft, error)
- func (s *Service) Recover(ctx context.Context) error
- func (s *Service) Retry(ctx context.Context, id draft.ID, confirm bool) (draft.Draft, error)
- func (s *Service) Send(ctx context.Context) (sent, failed int, err error)
- func (s *Service) Tick(ctx context.Context) (approved int, err error)
- type Store
Constants ¶
const NotConfirmed = "not confirmed after a restart"
NotConfirmed is the Error of a draft Recover found in sending and Verify could not confirm.
Variables ¶
var ( ErrNotFound = errors.New("no such draft") ErrConflict = errors.New("the draft changed state") ErrDisabled = errors.New("the draft's plugin is disabled or has no publisher") ErrDuplicate = errors.New("an open draft of the same rule and key exists") ErrNeedsConfirm = errors.New("the draft may have been posted; retry needs confirm") ErrInvalid = errors.New("invalid draft") )
var ErrUnknownEffect = errors.New("no implementation of the effect")
ErrUnknownEffect is an effect a draft declares that has no implementation for its provider.
var ErrUnknownOrigin = errors.New("unknown proposer")
ErrUnknownOrigin is a draft's proposing intent, workflow or turn that the manifests or the book do not know.
Functions ¶
Types ¶
type AppliedStore ¶ added in v0.2.0
type AppliedStore interface {
// Unapplied are the sent drafts that declare effects and whose
// EffectsAppliedAt is zero, oldest first.
Unapplied(ctx context.Context) ([]draft.Draft, error)
// MarkApplied stores at as the draft's EffectsAppliedAt.
MarkApplied(ctx context.Context, id draft.ID, at time.Time) error
}
AppliedStore keeps when a sent draft's effects were applied.
type Applier ¶ added in v0.2.0
type Applier interface {
Apply(ctx context.Context, d draft.Draft) error
// Pending are the sent drafts whose effects are not applied yet.
Pending(ctx context.Context) ([]draft.Draft, error)
}
Applier applies the Effects of a sent draft exactly once: each by its name, then the draft's EffectsAppliedAt, so a restart applies only those of drafts sent and not yet applied.
type EffectApplier ¶ added in v0.2.0
type EffectApplier struct {
Store AppliedStore
Effects EffectLookup
Clock port.Clock
}
EffectApplier is the Applier over a store and the effect implementations.
func (EffectApplier) Apply ¶ added in v0.2.0
Apply runs every effect d declares, in order, then marks d applied; a draft not sent, or already applied, is left as it is. When an effect fails nothing is marked, so the next Pending pass runs them all again: each effect is idempotent.
func (EffectApplier) Implements ¶ added in v0.2.0
func (a EffectApplier) Implements(p unit.ProviderID, name string) bool
type EffectLookup ¶ added in v0.2.0
type EffectLookup func(p unit.ProviderID, name string) (Effect, bool)
EffectLookup is the implementation of effect name for drafts of provider p; false when there is none.
type Effects ¶
type Effects func(p unit.ProviderID) (port.Effects, error)
Effects returns the publishing capability of a provider; an error wrapping ErrDisabled when its plugin is off or has no publisher.
type Evidence ¶
Evidence receives a sent draft's evidence for its items (wired to the items ledger, op "evidence").
func EvidenceTo ¶
func EvidenceTo(apply func(ctx context.Context, prov items.Provenance, ops []items.Op) error) Evidence
EvidenceTo is an Evidence that applies a sent draft's EvidenceOps through apply, with provenance effects.
type Facts ¶ added in v0.2.0
Facts reads the facts of unit u that a policy's rules read, scoped by workflow when it is set.
type Implementer ¶ added in v0.2.0
type Implementer interface {
Applier
Implements(p unit.ProviderID, name string) bool
}
Implementer is an Applier that says whether it has effect name for the drafts of provider p, so Propose refuses a draft it could never apply.
type ItemReader ¶
ItemReader reads a unit's items, for the confidence Would.Policy weighs.
type Manifests ¶
type Manifests interface {
// IntentApproval is the block of intent name, nil when it declares none; known is false for an unknown intent.
IntentApproval(name string) (p *draft.Policy, known bool)
// WorkflowApproval is the policy of the drafts of a turn workflow name
// started, of an intent whose block is intent: the workflow's block, else
// intent, with what the configuration lays over it; nil when none
// applies. known is false for an unknown workflow.
WorkflowApproval(name string, intent *draft.Policy) (p *draft.Policy, known bool)
// Turn is the intent of turn seq in u's book and the workflow that started it; ok is false when the book has no such turn.
Turn(ctx context.Context, u unit.Unit, seq int64) (intent, workflow string, ok bool, err error)
}
Manifests reads the [drafts.approval] blocks of the loaded intents and workflows, and the turns book.
type Policies ¶
type Policies interface {
For(ctx context.Context, u unit.Unit, o draft.Origin) (draft.Policy, error)
}
Policies resolves the approval policy of a proposal on u whose Policy is nil.
type Proposal ¶
type Proposal struct {
Unit unit.Unit
Items []string
Entry string
Kind draft.Kind
Target, Text, Reaction string
Origin draft.Origin
// Policy is the draft's approval policy; nil: resolved by
// Service.Policies from Origin.
Policy *draft.Policy
// Subject is the subject the proposer read, whose facts the policy's
// rules read; nil: Service.Facts reads the unit's.
Subject *draft.Subject
// Purpose and Delivery are the draft's shape; "" derives them from Kind
// (draft.ShapeOf), and a set Purpose with no Kind derives Kind
// (draft.KindOf).
Purpose string
Delivery draft.Delivery
// Effects are applied once the draft is sent, names of builtin.Effects.
Effects []string
// RepeatAfter is how long a settled draft of the same origin holds this
// proposal from being proposed again; zero keeps Service.RepeatAfter.
RepeatAfter time.Duration
}
type Resolver ¶
type Resolver struct {
Manifests Manifests
}
Resolver is the Policies of the manifests, for turn and session drafts only: the proposing turn's workflow's policy laid over its intent's block, else wait. The intent and workflow come from the turn in the book; an Origin that names others than the book's resolves to wait. Every other origin resolves to wait, so a rule's policy reaches a draft only through Proposal.Policy.
type Service ¶
type Service struct {
Store Store
Effects Effects
Policies Policies // nil resolves every proposal to wait
Facts Facts // nil: a policy whose rules read the unit's facts resolves to wait
// Broken names the workflows that failed to load; a delay draft of one
// waits for a person until it loads again.
Broken func() []string
Evidence Evidence // nil none
Items ItemReader // nil: no item counts as low confidence
Changes port.Changes
Clock port.Clock
Log func(format string, args ...any) // ids, states and kinds only; never text or tokens
// OnSent runs after a draft is stored as sent and its Evidence call (last-nudge stamps, plugin bookkeeping).
OnSent []func(ctx context.Context, d draft.Draft) error
// RepeatAfter is how long a dry_run draft keeps an auto proposal of its key from being stored again;
// zero keeps it for good.
RepeatAfter time.Duration
// Applier applies a sent draft's Effects; nil applies none.
Applier Applier
}
func (*Service) ApplyPending ¶ added in v0.2.0
ApplyPending applies the effects of every sent draft not applied yet: a draft sent before a restart, or whose effects failed.
func (*Service) List ¶
List is the drafts f selects, each with the delivery its provider's publisher posts it as.
func (*Service) NextDeadline ¶
NextDeadline is the earliest Deadline of a proposed delay draft; false when there is none.
func (*Service) RecordSent ¶
func (s *Service) RecordSent(ctx context.Context, p Proposal, ev draft.Evidence) (draft.Draft, error)
RecordSent stores a post already made outside the outbox (origin session) as sent.
func (*Service) Recover ¶
Recover runs once at daemon start: every sending draft -> Verify -> sent | failed, then the effects of every sent draft not applied yet; a draft whose provider answers ErrDisabled stays sending for the next Recover.
func (*Service) Retry ¶
Retry: failed -> approved. A draft that failed as "not confirmed after a restart" or with an Error starting "may have been posted" needs confirm true, else ErrNeedsConfirm.
type Store ¶
type Store interface {
Insert(ctx context.Context, d draft.Draft) (draft.Draft, error) // assigns ID
Get(ctx context.Context, id draft.ID) (draft.Draft, error) // ErrNotFound
List(ctx context.Context, f Filter) ([]draft.Draft, error) // newest first
// Update writes d only while the stored state is from and the stored Rev is d.Rev, and returns
// d with Rev bumped; ErrConflict otherwise.
Update(ctx context.Context, d draft.Draft, from draft.State) (draft.Draft, error)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package outboxtest holds fakes of the Outbox's ports.
|
Package outboxtest holds fakes of the Outbox's ports. |