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
- Variables
- type AheadStarter
- type Briefs
- type Firsts
- type Intake
- type Payloads
- type Readiness
- type Request
- type Service
- func (s *Service) Accept(ctx context.Context, r Request) (Intake, bool, error)
- func (s *Service) Cancel(ctx context.Context, seq int64) error
- func (s *Service) CancelFor(ctx context.Context, seq int64, note string) error
- func (s *Service) Drive(ctx context.Context, seq int64) (Intake, error)
- func (s *Service) Recover(ctx context.Context) ([]int64, error)
- func (s *Service) Without(ctx context.Context, seq int64) error
- type StartedTurn
- type Starter
- type State
- type Store
Constants ¶
const ( BriefReady = "ready" BriefWithout = "without" BriefOff = "off" )
The values of Intake.Brief.
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.
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" )
const ( CauseGaveUp = "gave_up" CauseBreaker = "breaker" CauseOff = "off" )
The causes of a Readiness that goes without the brief.
const ( WaitBriefing = "briefing" WaitRetry = "retry" )
The waits of a Readiness.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AheadStarter ¶
AheadStarter is a Starter that reads, before the service takes Lock, what its start would read under it; Start gets the returned context.
type Briefs ¶
type Briefs interface {
Ready(ctx context.Context, u unit.Unit, first bool) (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(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 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 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 sync.Locker
// 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)
// 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 ¶
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) Drive ¶
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.
type StartedTurn ¶
StartedTurn is the turn a Starter sent.
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)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package intaketest holds in-memory fakes of the intake ports.
|
Package intaketest holds in-memory fakes of the intake ports. |