G findings: distribution and gitea's package registry write through the held writer, so a restart neither drops nor rewrites their findings
Their in-memory open sets go. Builds: design 47 G A-32, A-29, A-37
This commit is contained in:
@@ -507,8 +507,8 @@ var findings = &holder.Findings{Logf: logf}
|
||||
func main() {
|
||||
// The tools bundle's findings go through the module's writer (design 47 G §689, A-16); it owns the transfers' kinds, the
|
||||
// program's writer the driver's.
|
||||
w, err := views.NewStdioWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: holder.Self, State: stdio.State("findings"), Kinds: holder.TransferFindingKinds, Observe: findings.Observed, Logf: logf})
|
||||
w, err := views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: holder.Self, State: stdio.State("findings"), Kinds: holder.TransferFindingKinds, Logf: logf})
|
||||
if err != nil {
|
||||
logf("%v", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -67,9 +67,9 @@ func run(ctx context.Context, getenv func(string) string) error {
|
||||
// The program's findings go through the module's writer (design 47 G §689); it owns the driver's kinds, the tools
|
||||
// bundle's writer the transfers'.
|
||||
findings := &holder.Findings{Logf: logger.Printf}
|
||||
w, err := views.NewWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
w, err := views.NewHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: holder.Self, Node: cred.Node, State: calls.State("findings"), Kinds: holder.DriverFindingKinds,
|
||||
JS: js, Conn: conn, Observe: findings.Observed, Logf: logger.Printf})
|
||||
JS: js, Conn: conn, Logf: logger.Printf})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package holder
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
meshconditions "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
@@ -25,26 +24,19 @@ type FindingWriter interface {
|
||||
}
|
||||
|
||||
// Findings keeps a bundle's open findings and says them through the module's writer (design 47 G §689, A-14): its `Say` is
|
||||
// the Finding callback of the Driver and the Holder, and its `Observed` is the writer's observe, so a statement covers
|
||||
// what is open.
|
||||
// the Finding callback of the Driver and the Holder; the writer is the held writer (views.HeldWriter), which holds what is open (A-29, A-32).
|
||||
type Findings struct {
|
||||
Writer FindingWriter
|
||||
Logf func(string, ...any)
|
||||
Now func() time.Time
|
||||
|
||||
mu sync.Mutex
|
||||
open map[string]meshconditions.Finding
|
||||
}
|
||||
|
||||
// Say raises (raised) or clears the finding of a kind about a subject. Its id is the seat's and the subject's, each escaped
|
||||
// as a key's name is (design 47 G A-14); the kind stays the bundle's own word.
|
||||
func (k *Findings) Say(kind, subject, words string, raised bool) {
|
||||
id := keyparts.EscapeName(Self) + "." + keyparts.EscapeName(subject)
|
||||
k.mu.Lock()
|
||||
defer k.mu.Unlock()
|
||||
key := views.FindingKey("seat", id, kind)
|
||||
if !raised {
|
||||
delete(k.open, key)
|
||||
if err := k.Writer.Clear(context.Background(), "seat", id, kind, "it no longer holds"); err != nil {
|
||||
k.Logf("the finding %s could not be cleared: %v", key, err)
|
||||
}
|
||||
@@ -57,26 +49,11 @@ func (k *Findings) Say(kind, subject, words string, raised bool) {
|
||||
f := meshconditions.Finding{Scope: "seat", ID: id, Kind: kind, Subject: meshconditions.Subject{Scope: "seat", ID: id},
|
||||
Severity: meshconditions.FindingSeverityWarning, Summary: words, Headline: words, Explanation: words,
|
||||
Source: kind, Observer: Self, At: at.UTC()}
|
||||
if k.open == nil {
|
||||
k.open = map[string]meshconditions.Finding{}
|
||||
}
|
||||
k.open[key] = f
|
||||
if err := k.Writer.Write(context.Background(), f); err != nil {
|
||||
k.Logf("the finding %s could not be written: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Observed is the findings open now, for the writer's statement (views.WriterConfig.Observe).
|
||||
func (k *Findings) Observed(context.Context) (views.Observed[meshconditions.Finding], error) {
|
||||
k.mu.Lock()
|
||||
defer k.mu.Unlock()
|
||||
var out views.Observed[meshconditions.Finding]
|
||||
for _, f := range k.open {
|
||||
out.Findings = append(out.Findings, f)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DeleteOldFindings deletes, once at a module's start, the findings the keys of an older form hold (design 47 G A-31): the form
|
||||
// `seat.<seat>.<kind>_<subject>`, whose kind is no kind the writer owns in its key, so the writer's own first statement does not
|
||||
// clear it. Only a key of one of kinds is deleted; the keys of the writer's form (`seat.<seat>.<subject>.<kind>`) are left.
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
meshconditions "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
@@ -24,26 +23,19 @@ type findingWriter interface {
|
||||
}
|
||||
|
||||
// Findings keeps a bundle's open findings and says them through the module's writer (design 47 G §689, A-14): its `Say` is
|
||||
// the Finding callback of the Driver and the Holder, and its `Observed` is the writer's observe, so a statement covers
|
||||
// what is open.
|
||||
// the Finding callback of the Driver and the Holder; the writer is the held writer (views.HeldWriter), which holds what is open (A-29, A-32).
|
||||
type Findings struct {
|
||||
Writer findingWriter
|
||||
Logf func(string, ...any)
|
||||
Now func() time.Time
|
||||
|
||||
mu sync.Mutex
|
||||
open map[string]meshconditions.Finding
|
||||
}
|
||||
|
||||
// Say raises (raised) or clears the finding of a kind about a subject. Its id is the seat's and the subject's, each escaped
|
||||
// as a key's name is (design 47 G A-14); the kind stays the bundle's own word.
|
||||
func (k *Findings) Say(kind, subject, words string, raised bool) {
|
||||
id := keyparts.EscapeName(packageseats.Self) + "." + keyparts.EscapeName(subject)
|
||||
k.mu.Lock()
|
||||
defer k.mu.Unlock()
|
||||
key := views.FindingKey("seat", id, kind)
|
||||
if !raised {
|
||||
delete(k.open, key)
|
||||
if err := k.Writer.Clear(context.Background(), "seat", id, kind, "it no longer holds"); err != nil {
|
||||
k.Logf("the finding %s could not be cleared: %v", key, err)
|
||||
}
|
||||
@@ -56,26 +48,11 @@ func (k *Findings) Say(kind, subject, words string, raised bool) {
|
||||
f := meshconditions.Finding{Scope: "seat", ID: id, Kind: kind, Subject: meshconditions.Subject{Scope: "seat", ID: id},
|
||||
Severity: meshconditions.FindingSeverityWarning, Summary: words, Headline: words, Explanation: words,
|
||||
Source: kind, Observer: packageseats.Self, At: at.UTC()}
|
||||
if k.open == nil {
|
||||
k.open = map[string]meshconditions.Finding{}
|
||||
}
|
||||
k.open[key] = f
|
||||
if err := k.Writer.Write(context.Background(), f); err != nil {
|
||||
k.Logf("the finding %s could not be written: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Observed is the findings open now, for the writer's statement (views.WriterConfig.Observe).
|
||||
func (k *Findings) Observed(context.Context) (views.Observed[meshconditions.Finding], error) {
|
||||
k.mu.Lock()
|
||||
defer k.mu.Unlock()
|
||||
var out views.Observed[meshconditions.Finding]
|
||||
for _, f := range k.open {
|
||||
out.Findings = append(out.Findings, f)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DeleteOldFindings deletes, once at a module's start, the findings the keys of an older form hold (design 47 G A-31): the form
|
||||
// `seat.<seat>.<kind>_<subject>`, whose kind is no kind the writer owns in its key, so the writer's own first statement does not
|
||||
// clear it. Only a key of one of kinds is deleted; the keys of the writer's form (`seat.<seat>.<subject>.<kind>`) are left.
|
||||
|
||||
@@ -30,8 +30,8 @@ var findings = &Findings{Logf: func(f string, a ...any) { fmt.Fprintf(os.Stderr,
|
||||
|
||||
func main() {
|
||||
// The bundle's findings go through the module's writer (design 47 G A-16).
|
||||
w, err := views.NewStdioWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: packageseats.Self, State: stdio.State("findings"), Kinds: findingKinds, Observe: findings.Observed})
|
||||
w, err := views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: packageseats.Self, State: stdio.State("findings"), Kinds: findingKinds})
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user