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 Effects
- type Evidence
- type Filter
- type ItemReader
- type Manifests
- type Policies
- type Proposal
- type Resolver
- type Service
- 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 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 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 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) (a *draft.Approval, known bool)
// WorkflowApproval is the block of workflow name, nil when it declares none; known is false for an unknown workflow.
WorkflowApproval(name string) (a *draft.Approval, 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 [draft_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.Approval, error)
}
Policies resolves the approval of a proposal on u whose Approval is nil.
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 block, then its intent's, else always. The intent and workflow come from the turn in the book; an Origin that names others than the book's resolves to always. Every other origin resolves to always, so a rule's policy reaches a draft only through Proposal.Approval.
type Service ¶
type Service struct {
Store Store
Effects Effects
Policies Policies // nil resolves every proposal to always
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
// ObservedFor is how long an observed draft keeps an auto proposal of its key from being observed again;
// zero keeps it for good.
ObservedFor time.Duration
}
func (*Service) NextDeadline ¶
NextDeadline is the earliest Deadline of a proposed window 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; 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)
}