An owed act met by the forge away (401 while the store was replaced) ended could not be performed and nothing performed it again. Each act is now a kept call at the module's pace (kept-call-pace-first, kept-call-pace-max) until owed-away-bound (60 minutes), then ends could not be performed naming every try. Before each try the bridge reads the pull request through the seat git's pull: one closed unmerged ends owed.ended not-needed, never performed. The gate's owed event gains record (the delivery record's source revision), kept with the act in performed, and bridge_owed_again by record and why performs again every act of that record that ended could not be performed, written in the hand-act log first. Builds: design 47 H2 §807, §775, §819, H-A-432
116 lines
4.6 KiB
Go
116 lines
4.6 KiB
Go
package groups
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// What a person asks of the bridge's performing of what is owed (novox/hq design 47 *What the gate owes the forge*): the
|
|
// tools bridge_owed (its consumers' backlog), bridge_owed_again and bridge_owed_drop write an ask into the state
|
|
// owed-asks and wait for the bridge's answer there, since the bridge is the other program
|
|
// and serves no request subject (ADR 0437 §4).
|
|
const (
|
|
// PerformedState is the bridge's state of the acts it performed, the `requires` entry performed.
|
|
PerformedState = "performed"
|
|
// OwedAsksState is the state of asks about what is owed, one key per kind of ask and act.
|
|
OwedAsksState = "owed-asks"
|
|
)
|
|
|
|
// OwedAsksBucket is its bucket on the bus, `<module>_<state>` of the module the bridge runs as, its credential's (A-296).
|
|
func OwedAsksBucket(module string) string { return module + "_" + OwedAsksState }
|
|
|
|
// The kinds of an owed ask.
|
|
const (
|
|
OwedAgain = "again"
|
|
OwedDrop = "drop"
|
|
OwedBacklog = "backlog"
|
|
)
|
|
|
|
// Backlog is one durable consumer of a seat's stream owed as the bridge reads it: the last event applied (its stream
|
|
// sequence), the events waiting and those delivered and not yet acknowledged, and the oldest of them.
|
|
type Backlog struct {
|
|
Stream string `json:"stream"`
|
|
Consumer string `json:"consumer"`
|
|
LastApplied uint64 `json:"last-applied"`
|
|
Waiting uint64 `json:"waiting"`
|
|
Held uint64 `json:"held"`
|
|
Oldest time.Time `json:"oldest,omitzero"`
|
|
OldestSecs int64 `json:"oldest-secs,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// OwedAsk is a value of owed-asks: what was asked (of the act Of said under ID, for again and drop), why, who and when,
|
|
// and once the bridge answered, when, what it came to (the outcome said as owed.ended) and its words; a backlog ask is
|
|
// answered with the consumers' backlog.
|
|
type OwedAsk struct {
|
|
Kind string `json:"kind"`
|
|
Of string `json:"of,omitempty"`
|
|
ID string `json:"id,omitempty"`
|
|
// Record, for again instead of an act, is a delivery record's source revision: every act of it that ended could not
|
|
// be performed is performed again (design 47 H2 §807, H-A-432 (1)).
|
|
Record string `json:"record,omitempty"`
|
|
Why string `json:"why,omitempty"`
|
|
By string `json:"by,omitempty"`
|
|
At time.Time `json:"at"`
|
|
Answered time.Time `json:"answered,omitzero"`
|
|
Outcome string `json:"outcome,omitempty"`
|
|
Answer string `json:"answer,omitempty"`
|
|
Backlog []Backlog `json:"backlog,omitempty"`
|
|
}
|
|
|
|
// Done says the bridge answered it.
|
|
func (a OwedAsk) Done() bool { return !a.Answered.IsZero() }
|
|
|
|
// NewOwedAsk is an ask's key and value: a backlog ask under the key backlog, an act's under its kind, its seat and its id
|
|
// (unpadded base64url, as an id may hold what a key may not). A drop says why.
|
|
func NewOwedAsk(kind, of, id, why, by string, at time.Time) (string, []byte, error) {
|
|
a := OwedAsk{Kind: kind, Of: of, ID: id, Why: strings.TrimSpace(why), By: by, At: at.UTC()}
|
|
key := kind
|
|
switch kind {
|
|
case OwedBacklog:
|
|
a.Of, a.ID = "", ""
|
|
case OwedAgain, OwedDrop:
|
|
if of == "" || id == "" {
|
|
return "", nil, fmt.Errorf("an owed act is named by the seat that said it and its id")
|
|
}
|
|
if kind == OwedDrop && a.Why == "" {
|
|
return "", nil, fmt.Errorf("a drop says why")
|
|
}
|
|
key = kind + "." + of + "." + base64.RawURLEncoding.EncodeToString([]byte(id))
|
|
default:
|
|
return "", nil, fmt.Errorf("no owed ask %q: again, drop or backlog", kind)
|
|
}
|
|
v, err := json.Marshal(a)
|
|
return key, v, err
|
|
}
|
|
|
|
// NewOwedRecordAsk is the key and value of an ask to perform again every act of one delivery record (its source revision,
|
|
// <branch>.<source>) that ended could not be performed: under again.record and the record (unpadded base64url). It says why.
|
|
func NewOwedRecordAsk(record, why, by string, at time.Time) (string, []byte, error) {
|
|
a := OwedAsk{Kind: OwedAgain, Record: strings.TrimSpace(record), Why: strings.TrimSpace(why), By: by, At: at.UTC()}
|
|
if a.Record == "" {
|
|
return "", nil, fmt.Errorf("a record is named by its source revision, <branch>.<source>")
|
|
}
|
|
if a.Why == "" {
|
|
return "", nil, fmt.Errorf("performing a record's acts again says why")
|
|
}
|
|
v, err := json.Marshal(a)
|
|
return OwedAgain + ".record." + base64.RawURLEncoding.EncodeToString([]byte(a.Record)), v, err
|
|
}
|
|
|
|
// DecodeOwedAsk reads a value of owed-asks.
|
|
func DecodeOwedAsk(data []byte) (OwedAsk, error) {
|
|
var a OwedAsk
|
|
if err := json.Unmarshal(data, &a); err != nil {
|
|
return a, err
|
|
}
|
|
switch a.Kind {
|
|
case OwedAgain, OwedDrop, OwedBacklog:
|
|
return a, nil
|
|
}
|
|
return a, fmt.Errorf("no owed ask %q", a.Kind)
|
|
}
|