outbox

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 11 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 outbox keeps the drafts the loop proposes and publishes the ones the user, or their approval policy, approved.

Index

Constants

View Source
const NotConfirmed = "not confirmed after a restart"

NotConfirmed is the Error of a draft Recover found in sending and Verify could not confirm.

Variables

View Source
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")
)
View Source
var ErrUnknownEffect = errors.New("no implementation of the effect")

ErrUnknownEffect is an effect a draft declares that has no implementation for its provider.

View Source
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

func EvidenceOps

func EvidenceOps(d draft.Draft) []items.Op

EvidenceOps are the items ledger ops that record sent draft d on each of its items; the caller applies them with provenance items.Effects.

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 Effect added in v0.2.0

type Effect func(ctx context.Context, d draft.Draft) error

Effect applies one declared effect of a sent draft.

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

func (a EffectApplier) Apply(ctx context.Context, d draft.Draft) error

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

func (EffectApplier) Pending added in v0.2.0

func (a EffectApplier) Pending(ctx context.Context) ([]draft.Draft, error)

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

type Evidence func(ctx context.Context, d draft.Draft) error

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

type Facts func(ctx context.Context, u unit.Unit, workflow string) (draft.Subject, error)

Facts reads the facts of unit u that a policy's rules read, scoped by workflow when it is set.

type Filter

type Filter struct {
	States    []draft.State
	Unit      *unit.Unit
	Entry     string
	Rule, Key string
	// Workflow keeps the drafts whose Origin.Workflow is it; "" any.
	Workflow string
}

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

type ItemReader interface {
	Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
}

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.

func (Resolver) For

func (r Resolver) For(ctx context.Context, u unit.Unit, o draft.Origin) (draft.Policy, error)

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

func (s *Service) ApplyPending(ctx context.Context) error

ApplyPending applies the effects of every sent draft not applied yet: a draft sent before a restart, or whose effects failed.

func (*Service) Approve

func (s *Service) Approve(ctx context.Context, id draft.ID, text *string) (draft.Draft, error)

func (*Service) Discard

func (s *Service) Discard(ctx context.Context, id draft.ID, reason string) (draft.Draft, error)

func (*Service) Edit

func (s *Service) Edit(ctx context.Context, id draft.ID, text string) (draft.Draft, error)

func (*Service) List

func (s *Service) List(ctx context.Context, f Filter) ([]draft.Draft, error)

List is the drafts f selects, each with the delivery its provider's publisher posts it as.

func (*Service) NextDeadline

func (s *Service) NextDeadline(ctx context.Context) (time.Time, bool, error)

NextDeadline is the earliest Deadline of a proposed delay draft; false when there is none.

func (*Service) Propose

func (s *Service) Propose(ctx context.Context, p Proposal) (draft.Draft, error)

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

func (s *Service) Recover(ctx context.Context) error

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

func (s *Service) Retry(ctx context.Context, id draft.ID, confirm bool) (draft.Draft, error)

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.

func (*Service) Send

func (s *Service) Send(ctx context.Context) (sent, failed int, err error)

Send is the sender pass: the effects of the sent drafts not applied yet, then every approved draft -> sending -> sent | failed, one Publish each, no retry.

func (*Service) Tick

func (s *Service) Tick(ctx context.Context) (approved int, err error)

Tick approves every proposed delay draft whose Deadline passed, through the same gate as Approve; a draft the gate refuses stays proposed.

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.

Jump to

Keyboard shortcuts

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