intake

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 14 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 intake runs a turn a user asks for: the request is accepted with a number at once, waits for the first turn's brief, then starts the turn.

Index

Constants

View Source
const (
	BriefReady   = "ready"
	BriefWithout = "without"
	BriefOff     = "off"
)

The values of Intake.Brief.

View Source
const (
	KindAccepted = "intake_accepted"
	KindBriefing = "intake_briefing"
	KindStarting = "intake_starting"
	KindStarted  = "intake_started"
	KindFailed   = "intake_failed"
	KindCanceled = "intake_canceled"
	KindGuidance = "intake_guidance"
	// KindLog is a notice published for each log line and never stored.
	KindLog = "intake_log"
)

The kinds of the events an intake's saves write, keyed by its seq, and intake_guidance by <seq>:<n> for its n-th replacement; Data is the note or the error.

View Source
const (
	NoteGuidance = "guidance replaced by a later request"
	NoteWithout  = "you started it without the brief"
	NoteNoBrief  = "asked to start without the brief"
	NoteStopped  = "the daemon stopped while starting the turn; ask again"
	NoteCanceled = "canceled by the user"
)
View Source
const (
	CauseGaveUp  = "gave_up"
	CauseBreaker = "breaker"
	CauseOff     = "off"
)

The causes of a Readiness that goes without the brief.

View Source
const (
	WaitBriefing = "briefing"
	WaitRetry    = "retry"
)

The waits of a Readiness.

View Source
const SourceSession = "session"

BriefState is what an intake shows of its unit's brief: whether one is recorded, the attempts that failed since its last success, whether the queue gave up on it, the error of a last run that failed, and when it tries again. SourceSession is the source of an intake a managed session asked for.

Variables

View Source
var (
	ErrUnknown    = errors.New("no such intake")
	ErrNotWaiting = errors.New("the intake is not waiting")
	ErrDriven     = errors.New("the intake is already being driven")
)

Functions

This section is empty.

Types

type AheadStarter

type AheadStarter interface {
	ReadAhead(ctx context.Context, i Intake) context.Context
}

AheadStarter is a Starter that reads, before the service takes Lock, what its start would read under it; Start gets the returned context.

type BriefState added in v0.3.0

type BriefState struct {
	Found     bool
	Failures  int
	GaveUp    bool
	LastError string
	RetryAt   time.Time
}

type Briefs

type Briefs interface {
	// Ready answers for a turn of u; need are the brief intent's extra
	// fields the turn's intent needs, which a first turn waits for.
	Ready(ctx context.Context, u unit.Unit, first bool, need []string) (Readiness, error)
	// Changed is closed by the next end of a brief run of the unit after the
	// call, so a run that ends while the caller asks Ready still wakes it;
	// the func releases it.
	Changed(ctx context.Context, u unit.Unit) (<-chan struct{}, func())
	// Unwant drops the want of a brief once no intake waits on it.
	Unwant(ctx context.Context, u unit.Unit) error
}

type Firsts

type Firsts interface {
	First(ctx context.Context, u unit.Unit) (bool, error)
}

type Intake

type Intake struct {
	Seq                                         int64
	Unit                                        unit.Unit
	Intent                                      turn.Intent
	Source                                      string
	Request                                     []byte
	State                                       State
	Brief, Note                                 string
	AcceptedAt, BriefingAt, StartingAt, EndedAt time.Time
	TurnSeq                                     int64
	TurnID, Error                               string
	Log                                         []string
}

type Payloads

type Payloads interface {
	WithGuidance(payload []byte, guidance string) ([]byte, error)
}

Payloads rewrites a stored request's guidance, for a joining request.

type Readiness

type Readiness struct {
	Go, Without     bool
	Cause           string
	Wait            string
	Attempt         int
	Note, LastError string
	Next, Since     time.Time
}

Readiness is the brief queue's answer for a pull request: Go starts the turn, with the brief unless Without, and Cause says why without; otherwise the intake waits, Wait and Attempt saying on what, until the brief changes or Next. LastError is the failure of attempt Attempt-1; for CauseGaveUp, Attempt counts the failed attempts and LastError is the last one's; for CauseBreaker, Since and LastError say since when and why briefs are unavailable.

type Request

type Request struct {
	Unit     unit.Unit
	Intent   turn.Intent
	Source   string
	Payload  []byte
	Guidance string
	NoBrief  bool
	// CanJoin refuses, with its error, to join the open intake of the
	// request's pull request and intent; nil joins any.
	CanJoin func(open Intake) error
}

type Service

type Service struct {
	Store    Store
	Briefs   Briefs
	Firsts   Firsts
	Starter  Starter
	Payloads Payloads
	Clock    port.Clock
	Pub      port.Publisher
	// Lock is the daemon's loop mutex, held only while the turn starts.
	Lock *lock.Mutex
	// After is time.After when nil.
	After func(time.Duration) <-chan time.Time
	// Log reports what fails after an intake's change is saved; nil drops
	// it.
	Log func(format string, args ...any)
	// Needs are the brief fields an intent needs, its manifest's
	// brief.need; nil needs none.
	Needs func(intent string) []string
	// contains filtered or unexported fields
}

Service drives intakes. The daemon accepts a request, then drives the intake on its own goroutine; Without and Cancel wake that goroutine.

func (*Service) Accept

func (s *Service) Accept(ctx context.Context, r Request) (Intake, bool, error)

Accept answers a new intake, or the open one of the request's pull request and intent, joined. A joined intake still waiting takes the request's guidance and NoBrief; one already starting is answered unchanged, and the caller tells the user the request changed nothing.

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, seq int64) error

func (*Service) CancelFor

func (s *Service) CancelFor(ctx context.Context, seq int64, note string) error

CancelFor cancels a waiting intake with note as the reason.

func (*Service) Drive

func (s *Service) Drive(ctx context.Context, seq int64) (Intake, error)

Drive takes the intake from where it stands to its end: it waits for the brief while one is coming, then starts the turn. A Starter's error fails the intake and is not returned; a canceled ctx leaves a waiting intake as it is, for Recover. Only one Drive of an intake runs at a time; another answers ErrDriven.

func (*Service) Recover

func (s *Service) Recover(ctx context.Context) ([]int64, error)

Recover fails the intakes a stopped daemon left starting, since their action may have half run, and answers the waiting ones for the caller to drive again.

func (*Service) Without

func (s *Service) Without(ctx context.Context, seq int64) error

Without makes a waiting intake start without the brief.

type StartedTurn

type StartedTurn struct {
	TurnSeq int64
	TurnID  string
}

StartedTurn is the turn a Starter sent.

type Starter

type Starter interface {
	Start(ctx context.Context, i Intake, out io.Writer) (StartedTurn, error)
}

type State

type State string
const (
	Accepted State = "accepted"
	Briefing State = "briefing"
	Starting State = "starting"
	Started  State = "started"
	Failed   State = "failed"
	Canceled State = "canceled"
)

func (State) Open

func (s State) Open() bool

Open tells a state that holds its pull request and intent: a request for them joins the intake.

type Store

type Store interface {
	// Accept stores i under a new Seq and writes evs keyed by it, in one
	// transaction. When i's pull request and intent have an open intake, it
	// stores nothing and answers that intake, joined.
	Accept(ctx context.Context, i Intake, evs ...port.Event) (Intake, bool, error)
	Save(ctx context.Context, i Intake, evs ...port.Event) error
	Intake(ctx context.Context, seq int64) (Intake, bool, error)
	// Open lists the open intakes, oldest first.
	Open(ctx context.Context) ([]Intake, error)
}

type StoredBrief added in v0.3.0

type StoredBrief struct {
	State BriefState
	JSON  string
	Took  time.Duration
}

StoredBrief is a unit's stored brief as an intake reads it: its state, the brief's JSON and how long its last run took, zero when unknown.

Directories

Path Synopsis
Package intaketest holds in-memory fakes of the intake ports.
Package intaketest holds in-memory fakes of the intake ports.

Jump to

Keyboard shortcuts

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