Asking whether the merge contains the held commit refused forward merges forever on a diverged or rewritten main or a squash-merged registered head, failed every later merge when the forge no longer had the held commit, and cost one forge call per held commit. The question is now the reverse: a merge is kept back only when it is in the taken merge and differs from it. A merged message asks it once, before it writes anything, and a late message writes no module, deletion, placement or taken key. A take-in asks it once for its module. A 404 is not known to be older and is written, and said; any other failure to say leaves the message for redelivery.
61 lines
2.5 KiB
Go
61 lines
2.5 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// What the indexer heard of the forge bridge's stream FORGE (issue 1126 note 76): no tool read FORGE's messages, so a merge
|
|
// written back over a later one could not be traced to a late or repeated message. The indexer writes, for each message
|
|
// it handles, one value under the key forge of its state heard: the message's subject, stream sequence, how often the
|
|
// server delivered it, when it was published and handled, what it names and what the indexer did with it. The state keeps
|
|
// the last 64 values (its history); mesh-delivery-view's indexer_heard reads them, newest first, with their times.
|
|
const (
|
|
HeardState = "heard"
|
|
HeardBucket = delivery.IndexerModule + "_" + HeardState
|
|
HeardKey = "forge"
|
|
// What the indexer did with a message.
|
|
HeardApplied = "applied"
|
|
HeardLeft = "left for redelivery"
|
|
HeardDropped = "dropped"
|
|
)
|
|
|
|
// Heard is one FORGE message as the indexer handled it.
|
|
type Heard struct {
|
|
V int `json:"v"`
|
|
Subject string `json:"subject"`
|
|
Sequence uint64 `json:"sequence"` // the stream's sequence of the message
|
|
Delivered uint64 `json:"delivered,omitempty"` // how often the server delivered it to the indexer, this time included
|
|
Published time.Time `json:"published,omitzero"`
|
|
Handled time.Time `json:"handled"`
|
|
Kind string `json:"kind,omitempty"`
|
|
Repository string `json:"repository,omitempty"`
|
|
Number int `json:"number,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
Commit string `json:"commit,omitempty"` // the merge commit of a merged message, else the pull request's head
|
|
Outcome string `json:"outcome"`
|
|
Words string `json:"words,omitempty"` // why it was left or dropped
|
|
Written []string `json:"written,omitempty"` // the modules a merged message wrote
|
|
Late string `json:"late,omitempty"` // the taken merge a merged message is older than: nothing of it was written (order.go)
|
|
}
|
|
|
|
// Applied is what Apply did with a merged message's modules: the keys written, and, for a message older than the
|
|
// repository's taken merge, that merge (nothing was written).
|
|
type Applied struct {
|
|
Written []string
|
|
Late string
|
|
}
|
|
|
|
// WriteHeard writes h as the newest value of heard.forge.
|
|
func WriteHeard(ctx context.Context, st Store, h Heard) error {
|
|
h.V = 1
|
|
data, err := json.Marshal(h)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return write(ctx, st, HeardKey, func([]byte, bool) ([]byte, bool, error) { return data, false, nil })
|
|
}
|