delivery

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package delivery contains the pure delivery state machine. It performs no I/O; the host supplies a plan.DeliverySink and persists records.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("delivery record not found")

Functions

func CanTransition

func CanTransition(from, to State) bool

CanTransition reports whether the state machine allows from -> to.

func ValidateTransition

func ValidateTransition(from, to State) error

Types

type Manager

type Manager struct {
	Store       Store
	Sink        plan.DeliverySink
	Verifier    plan.Verifier
	CleanupSink plan.CleanupSink
}

Manager is the host-agnostic delivery state machine. It requires a Store and a host-provided DeliverySink; it ships no uploader/executor.

func NewManager

func NewManager(store Store, sink plan.DeliverySink) *Manager

func (*Manager) Cleanup

func (m *Manager) Cleanup(ctx context.Context, id int64) (*Record, error)

Cleanup invokes the host cleanup sink and advances registered -> cleaned.

func (*Manager) Deliver

func (m *Manager) Deliver(ctx context.Context, rec *Record) (*Record, error)

Deliver creates a pending record, invokes the host sink, and advances to delivered/failed.

func (*Manager) Fail

func (m *Manager) Fail(ctx context.Context, id int64, msg string) (*Record, error)

Fail marks a record failed.

func (*Manager) MarkRegistered

func (m *Manager) MarkRegistered(ctx context.Context, id int64) (*Record, error)

MarkRegistered advances verified -> registered (the host has created a session after verification).

func (*Manager) Verify

func (m *Manager) Verify(ctx context.Context, id int64) (*Record, error)

Verify runs the host verifier and advances delivered -> verified.

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore is the reference Store implementation.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Create

func (m *MemoryStore) Create(_ context.Context, rec *Record) (int64, error)

func (*MemoryStore) Get

func (m *MemoryStore) Get(_ context.Context, id int64) (*Record, error)

func (*MemoryStore) List

func (m *MemoryStore) List(_ context.Context, projectID int64, limit int) ([]*Record, error)

func (*MemoryStore) Update

func (m *MemoryStore) Update(_ context.Context, rec *Record) error

type Record

type Record struct {
	ID        int64
	ProjectID int64
	TaskID    string
	State     State
	Plan      plan.DeliveryPlan
	Result    *plan.DeliveryResult
	Message   string

	// Host metadata (mapped by the host Store).
	PayloadPath      string
	UploadTranscript string
	UploadTrafficID  string
	VerifyOutput     string
	VerifyTrafficID  string
	Error            string
	CreatedBy        string
	Remark           string
	Variant          string
	ConnectionID     *int64
	CleanedAt        *time.Time

	CreatedAt time.Time
	UpdatedAt time.Time
}

Record is a host-persisted delivery record. The host owns storage; this struct is only the shared shape.

type State

type State string
const (
	Pending    State = "pending"
	Delivered  State = "delivered"
	Verified   State = "verified"
	Registered State = "registered"
	Cleaned    State = "cleaned"
	Failed     State = "failed"
)

type Store

type Store interface {
	Create(ctx context.Context, rec *Record) (int64, error)
	Update(ctx context.Context, rec *Record) error
	Get(ctx context.Context, id int64) (*Record, error)
	List(ctx context.Context, projectID int64, limit int) ([]*Record, error)
}

Store is the persistence contract. The reference implementation is MemoryStore; a host may implement PostgreSQL/MySQL/etc. The contract tests should run against MemoryStore first.

Jump to

Keyboard shortcuts

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