Documentation
¶
Overview ¶
Package state is the engine's one writer for a repo's store: every change to ideas, pursuits, plans, intents and timers is a command applied one at a time in one transaction that appends its event. Reads come from the state tables; events are never replayed to answer one. Outside work runs as an intent off the loop, and its kind's Record stores what it found with its intent.done; a timer kind can be ensured on open.
Index ¶
- Variables
- type Command
- type Event
- type Intent
- type IntentKind
- type Options
- type State
- type Timer
- type TimerKind
- type Tx
- func (tx *Tx) DeleteTimer(kind, key string) error
- func (tx *Tx) Event(kind, subject string, subjectID int64, person string, data any) error
- func (tx *Tx) Exec(query string, args ...any) (sql.Result, error)
- func (tx *Tx) Intent(kind string, payload any) (id int64, err error)
- func (tx *Tx) Now() time.Time
- func (tx *Tx) Query(query string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryRow(query string, args ...any) *sql.Row
- func (tx *Tx) SetTimer(kind, key string, due time.Time, payload any) error
- func (tx *Tx) StoreDir() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned by Submit once the State is closed. ErrClosed = errors.New("the repo's state is closed") // ErrNoEvent refuses a command that changed state rows and appended no event. ErrNoEvent = errors.New("the command changed state and appended no event; nothing was written") )
Functions ¶
This section is empty.
Types ¶
type Command ¶
Command is one state change, run on the loop inside one write transaction. It uses only its Tx: calling Submit, Events or Close would wait on itself.
type Event ¶
type Event struct {
At time.Time
Kind, Subject string
SubjectID int64
Person string
Data json.RawMessage
}
Event is one row of the events table.
type Intent ¶
type Intent struct {
ID int64
Kind string
Payload json.RawMessage
Attempts int
}
Intent is one pending intent, as its kind's Do sees it.
type IntentKind ¶
type IntentKind struct {
Name string
Repeat string // required
Check func(payload json.RawMessage) error
Do func(ctx context.Context, in Intent) (result string, err error)
Record func(tx *Tx, in Intent, result string) error
}
IntentKind names a kind of intent. Repeat says, in one sentence, why carrying it out twice is safe. Check, if set, refuses a bad payload when the intent is written. Do runs off the loop, under a ctx that Close ends. Record, if set, stores what a successful Do found, in the transaction that marks the intent done; if it fails, nothing is kept and Do counts as failed.
type Options ¶
type Options struct {
StoreDir string
Now func() time.Time
Timers []TimerKind
Intents []IntentKind
}
Options configures a State. Now defaults to time.Now. Timers and Intents hold extra kinds (a TimerKind's Key is ensured on open; an IntentKind's Record keeps what Do found); retention and log.append are always present.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the one writer for a store's engine tables: a loop that applies commands and fires due timers one at a time, and a worker for intents.
func Open ¶
Open ensures the keyed timers, loads the next due time and the pending count, and starts the loop and the worker. Close it before the store.
func (*State) Close ¶
Close stops taking commands and cuts short the intent in hand; it returns once both have stopped, or with ctx's error.
func (*State) Events ¶
Events returns the newest events first (by id). limit is clamped to 1..500; 0 is 50.
func (*State) NextTimer ¶
NextTimer returns the earliest due time of the timers this engine can fire, from memory. Timers of a kind it does not register are left out.
func (*State) PendingIntents ¶
PendingIntents counts, from memory, the pending intents of registered kinds.
type TimerKind ¶
type TimerKind struct {
Name string
Fire func(tx *Tx, t Timer) error
Key string
Delay time.Duration
}
TimerKind names a kind of timer and what the loop does when one is due. Fire runs as a command: it may set the same (kind, key) again with tx.SetTimer; if it does not, the row is deleted in the same transaction. With a Key, Open ensures that timer, due within Delay (0 is at once).
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a command's view of its transaction: state rows, the event, intents, timers and the clock. It is refused once the command has returned.
func (*Tx) DeleteTimer ¶
DeleteTimer removes the timer (kind, key), if it exists.
func (*Tx) Event ¶
Event appends the command's event, at the command's time. A subjectID of 0 and a person of "" are stored as NULL. data is a JSON object; nil is {}.
func (*Tx) Intent ¶
Intent writes a pending intent, due now, in the command's transaction. The kind must be registered and its Check must accept the payload; nil is {}.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package evidence is the engine's record of engineering evidence: a durable poll that observes version control, and the forge when there is one, and keeps each fact once in the store, with the facts' retention and their reads.
|
Package evidence is the engine's record of engineering evidence: a durable poll that observes version control, and the forge when there is one, and keeps each fact once in the store, with the facts' retention and their reads. |
|
Package plan is the engine's commands and reads on a pursuit's plan and its progress: each revision kept with its reason, which change a session works on, tokens spent added and checked against the appetite in the same transaction, the circuit breaker, and the Needs you items they raise; each change one command with its event.
|
Package plan is the engine's commands and reads on a pursuit's plan and its progress: each revision kept with its reason, which change a session works on, tokens spent added and checked against the appetite in the same transaction, the circuit breaker, and the Needs you items they raise; each change one command with its event. |
|
Package work is the engine's commands and reads on ideas and pursuits: each change one command in one transaction with its event.
|
Package work is the engine's commands and reads on ideas and pursuits: each change one command in one transaction with its event. |