Deletes the placement and candidate writes, the reread tool and its forge reads, the two buckets and the placement-changed event. D1a and D1b are one commit: the index package, the named reads, the tools and the manifest do not compile apart.
68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package index
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// The indexer's doing tool (novox/hq issue 1945; the instruction "tools are how a module is spoken to"): indexer_take_in
|
|
// reads a registered module's manifest now and writes it to the modules state. The tools bundle serves it through the tool
|
|
// runner; the indexer's process serves no request subject (ADR 0437 §4), so the tool writes an ask into the indexer's
|
|
// state takeins, which the indexer watches and answers there, as the builder answers builder_ask_again. The read tools
|
|
// of the indexer's states stay in mesh-delivery-view.
|
|
const (
|
|
TakeInTool = "indexer_take_in"
|
|
// TakeInsState is the indexer's state of take-in asks: the bucket mesh-delivery-indexer_takeins, keyed as the modules state.
|
|
TakeInsState = "takeins"
|
|
TakeInsBucket = delivery.IndexerModule + "_" + TakeInsState
|
|
)
|
|
|
|
// TakeInAsk is a value of the takeins state: which module a person asked to be taken in, why, who and when, and, once the
|
|
// indexer read it, its answer.
|
|
type TakeInAsk struct {
|
|
V int `json:"v"`
|
|
Module string `json:"module,omitempty"`
|
|
Why string `json:"why,omitempty"`
|
|
By string `json:"by,omitempty"`
|
|
At time.Time `json:"at"`
|
|
Result *TakenIn `json:"result,omitempty"`
|
|
Answered time.Time `json:"answered,omitzero"`
|
|
}
|
|
|
|
// Done says the ask is answered.
|
|
func (a TakeInAsk) Done() bool { return !a.Answered.IsZero() && a.Result != nil }
|
|
|
|
// DecodeTakeIn reads a takeins value.
|
|
func DecodeTakeIn(data []byte) (TakeInAsk, error) {
|
|
var a TakeInAsk
|
|
if err := json.Unmarshal(data, &a); err != nil {
|
|
return a, err
|
|
}
|
|
if a.V != 1 {
|
|
return a, fmt.Errorf("a takeins value of version %d, not 1", a.V)
|
|
}
|
|
if a.Module == "" {
|
|
return a, errors.New("a takeins value naming no module")
|
|
}
|
|
return a, nil
|
|
}
|
|
|
|
// NewTakeIn is the value indexer_take_in writes for a module: its key and the value.
|
|
func NewTakeIn(module, why, by string, at time.Time) (string, []byte, error) {
|
|
module = strings.TrimSpace(module)
|
|
if module == "" {
|
|
return "", nil, errors.New("name the module to take in (module)")
|
|
}
|
|
key, err := delivery.ModulesKey(module)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
data, err := json.Marshal(TakeInAsk{V: 1, Module: module, Why: strings.TrimSpace(why), By: by, At: at.UTC()})
|
|
return key, data, err
|
|
}
|