Files
mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg/owed.go
T
jschoubben 13d960a120 F1: an owed act failing on a part away stays owed, and a record's acts are performed again
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
2026-11-22 01:46:49 +01:00

78 lines
3.0 KiB
Go

package forgemsg
import (
"encoding/json"
"fmt"
"slices"
"time"
)
// OwedEndedEvent is the name of an owed act's outcome on the forge bridge's stream `forge` (design 47 G §164): the
// bridge says it for each act the gate or the checker said as the event `owed`. Its two parts are no repository's
// forge event (`forge.<owner>.<name>.<kind>`).
const OwedEndedEvent = "owed.ended"
// The outcomes of an owed act (design 47 G §164, §168): performed, refused (the forge's own words), could not be
// performed (the forge did not answer within the bridge's owed-away-bound, naming every try, or answered an error),
// undecodable (an act the bridge cannot read, with why), from the tool `bridge_owed_drop`, dropped, and not-needed (the
// act's pull request closed unmerged, read before a try, so it is not performed; design 47 H2 §807, H-A-432 (2)).
const (
OwedPerformed = "performed"
OwedRefused = "refused"
OwedCouldNotBePerformed = "could not be performed"
OwedUndecodable = "undecodable"
OwedDropped = "dropped"
OwedNotNeeded = "not-needed"
)
// OwedOutcomes are the outcomes an owed.ended says, one of them.
var OwedOutcomes = []string{OwedPerformed, OwedRefused, OwedCouldNotBePerformed, OwedUndecodable, OwedDropped, OwedNotNeeded}
// OwedEnded is an owed act's outcome (design 47 G §164): the act's id and one outcome, with the words of any outcome
// but performed. Of is the seat that said the act (mesh-delivery for the gate's), so it hears its own ids (§164). An act the bridge cannot decode may name no id.
type OwedEnded struct {
V int `json:"v"`
Of string `json:"of"`
ID string `json:"id,omitempty"`
Outcome string `json:"outcome"`
Words string `json:"words,omitempty"`
At time.Time `json:"at"`
}
func (e OwedEnded) check() error {
switch {
case e.Of == "":
return fmt.Errorf("an owed act's outcome names no seat that said it")
case !slices.Contains(OwedOutcomes, e.Outcome):
return fmt.Errorf("the outcome %q of an owed act is none of %v", e.Outcome, OwedOutcomes)
case e.ID == "" && e.Outcome != OwedUndecodable:
return fmt.Errorf("the outcome %s of an owed act names no id", e.Outcome)
case e.Outcome != OwedPerformed && e.Words == "":
return fmt.Errorf("the outcome %s of the owed act %s says no words", e.Outcome, e.ID)
case e.At.IsZero():
return fmt.Errorf("the outcome of the owed act %s says no time", e.ID)
}
return nil
}
// EncodeOwedEnded is e as JSON at Version; it refuses what check refuses.
func EncodeOwedEnded(e OwedEnded) ([]byte, error) {
if err := e.check(); err != nil {
return nil, err
}
e.V = Version
return json.Marshal(e)
}
// DecodeOwedEnded reads an owed act's outcome; it refuses an unknown version and what EncodeOwedEnded refuses.
func DecodeOwedEnded(data []byte) (OwedEnded, error) {
var e OwedEnded
if err := decode(data, &e); err != nil {
return OwedEnded{}, err
}
if err := e.check(); err != nil {
return OwedEnded{}, err
}
return e, nil
}