A message heard on the forge is the forge bridge heard, the callee of the call: after each one a merge unread since CallUnansweredAfter or longer writes the finding naming the bridge's call, and a merge no longer unread clears it. While nothing is heard on the forge (the bridge's machine away) no finding is written; the merge is read again when the forge is heard. No timer. Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
70 lines
3.1 KiB
Go
70 lines
3.1 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
|
)
|
|
|
|
// **A merged message unread past five minutes, the forge heard, is a finding** (issue 1966 note 153; novox/hq ADR 0668 §3).
|
|
// The indexer's call for a merged message is a kept call: a transport fault leaves the merge unread (Pending.Unread) and
|
|
// it is read again after every message heard on the forge (UnreadAgain). A message heard on the forge is the forge bridge
|
|
// heard, the callee of that call: so after each one, a merge still unread since meshconditionsclient.CallUnansweredAfter
|
|
// or longer is the finding call-unanswered in the indexer's findings, which the condition keeper raises, and a merge no
|
|
// longer unread (read, taken in, covered or dropped) clears its finding. While nothing is heard on the forge (the bridge's
|
|
// machine away) no finding is written: the merge stays unread and is read again when the forge is heard. No timer.
|
|
|
|
// UnreadCallee is the call the finding names: the forge bridge's tool for one merged message.
|
|
const UnreadCallee = ForgeBridgeModule + ".bridge_merged_message"
|
|
|
|
// unreadCallID is the finding's id for the pending key: the merge it waits on.
|
|
func unreadCallID(key string) string { return "merged-message." + key }
|
|
|
|
// unreadFindings raises the finding of every merge of entries unread past the bound and clears the finding of every other.
|
|
func (ix *Indexer) unreadFindings(ctx context.Context, entries []PendingEntry) {
|
|
if ix.Findings == nil {
|
|
return
|
|
}
|
|
unread := map[string]bool{}
|
|
for _, e := range entries {
|
|
if e.Value.Unread == "" {
|
|
continue
|
|
}
|
|
unread[mcc.Key(mcc.ScopeCall, unreadCallID(e.Key), mcc.KindCallUnanswered)] = true
|
|
since := e.Value.UnreadSince
|
|
if since.IsZero() || ix.now().Sub(since) < mcc.CallUnansweredAfter {
|
|
continue
|
|
}
|
|
o := mcc.CallUnanswered(unreadCallID(e.Key), UnreadCallee, "", e.Value.Unread, "indexer."+mcc.KindCallUnanswered, since)
|
|
o.Needs = TakeInPendingTool + " reads the merge again now; " + PendingTool + " shows it unread."
|
|
key := o.Key()
|
|
if err := write(ctx, ix.Findings, key, func(value []byte, found bool) ([]byte, bool, error) {
|
|
if found {
|
|
if f, err := mcc.DecodeFinding(value); err == nil && f.Summary == o.Summary {
|
|
return nil, false, nil
|
|
}
|
|
}
|
|
data, err := mcc.EncodeFinding(o.Finding(Module, "", ix.now().UTC()))
|
|
return data, false, err
|
|
}); err != nil {
|
|
ix.logf("take-in: the finding %s is not written: %v", key, err)
|
|
} else {
|
|
ix.logf("take-in: %s (%s#%d) is unread since %s and the forge is heard: the finding %s", e.Key, e.Forge.Repository, e.Forge.Number, since.Format("2006-01-02T15:04:05Z07:00"), key)
|
|
}
|
|
}
|
|
keys, err := ix.Findings.Keys(ctx)
|
|
if err != nil {
|
|
return
|
|
}
|
|
prefix, suffix := mcc.ScopeCall+"."+unreadCallID(""), "."+mcc.KindCallUnanswered
|
|
for _, k := range keys {
|
|
if !strings.HasPrefix(k, prefix) || !strings.HasSuffix(k, suffix) || unread[k] {
|
|
continue
|
|
}
|
|
if err := write(ctx, ix.Findings, k, func(_ []byte, found bool) ([]byte, bool, error) { return nil, found, nil }); err != nil {
|
|
ix.logf("take-in: the finding %s is not cleared: %v", k, err)
|
|
}
|
|
}
|
|
}
|