N2: the keeper withdraws a refused drop's or recreate's ask on operator-channel
A refused request leaves nothing for the operator to answer, so its ask is cancelled in the same pass. Builds: design 47 H2 §813 (6)
This commit is contained in:
@@ -219,6 +219,9 @@ func runKeeper(ctx context.Context, getenv func(string) string, logOut io.Writer
|
||||
return err
|
||||
},
|
||||
Warrant: WarrantFrom(conn.Ask), Finding: writer,
|
||||
Cancel: func(id string) error {
|
||||
return conn.Accept("operator-channel", "cancel", map[string]string{"id": id}, stdio.EmitOptions{MessageID: "cancel." + id})
|
||||
},
|
||||
Logf: logger.Printf,
|
||||
Raise: percent(getenv, "MESH_NATS_FULL_RAISE", 75), Clear: percent(getenv, "MESH_NATS_FULL_CLEAR", 70),
|
||||
// The settings snapshots-cap (20 GiB) and snapshot-keep-days (90) of the manifest, read from the file it declares
|
||||
|
||||
@@ -349,8 +349,11 @@ type Keeper struct {
|
||||
// Act records a hand act through the seat mesh-hand-acts; Warrant reads the router's record of an ask.
|
||||
Act func(what, why, cause string) error
|
||||
Warrant func(askID string) (*oc.Ask, *oc.Warrant, error)
|
||||
Now func() time.Time
|
||||
Logf func(string, ...any)
|
||||
// Cancel takes an ask back on the seat operator-channel (ADR 0259 §3's cancel): a drop or recreate the keeper refuses at
|
||||
// once withdraws the ask its tool raised, in the same pass (design 47 H2 §813 (6)).
|
||||
Cancel func(askID string) error
|
||||
Now func() time.Time
|
||||
Logf func(string, ...any)
|
||||
// Raise and Clear are the fill marks in percent (ADR 0595 §6): settings of the bus module, 75 and 70 by default.
|
||||
Raise, Clear int64
|
||||
// Files are the snapshot files (the disk when nil); SnapshotsCap the cap of their directory in bytes and
|
||||
|
||||
@@ -846,6 +846,26 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
if got.Done.IsZero() || got.Waiting != "" || !strings.Contains(got.Error, "refused") || !strings.Contains(got.Error, w.Words) || len(bus.deleted) != 0 {
|
||||
t.Errorf("ended %+v, deleted %v: the router's refusal and its words, nothing removed", got, bus.deleted)
|
||||
}
|
||||
// Design 47 H2 §813 (6): the refused request withdraws its ask in the same pass; a cancel that fails is said.
|
||||
var cancelled []string
|
||||
k.Cancel = func(id string) error {
|
||||
cancelled = append(cancelled, id)
|
||||
if id == "bus-2" {
|
||||
return errors.New("no responders")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for _, r := range []Request{{ID: "rc", Verb: VerbRecreate, Module: "m", Local: "drafts", Ask: "bus-1", Caller: "person.jo"},
|
||||
{ID: "rd", Verb: VerbDrop, Module: "m", Local: "drafts", Ask: "bus-2", Caller: "person.jo"}} {
|
||||
raw, _ = json.Marshal(r)
|
||||
_, _ = store.Put(StateRequests, r.ID, raw)
|
||||
}
|
||||
k.ActOnRequests()
|
||||
raw, _, _, _ = store.Get(StateRequests, "rd")
|
||||
_ = json.Unmarshal(raw, &got)
|
||||
if fmt.Sprint(cancelled) != "[bus-1 bus-2]" || !strings.Contains(got.Error, "bus-2 could not be withdrawn: no responders") {
|
||||
t.Errorf("cancelled %v, ended %+v: each refused request's ask withdrawn once, a failed cancel said", cancelled, got)
|
||||
}
|
||||
}},
|
||||
{"a drop waits for the warrant, refuses another act's, then acts after a snapshot", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
store := k.Store.(*memStore)
|
||||
|
||||
@@ -169,6 +169,7 @@ func (k *Keeper) ActOnRequests() {
|
||||
r.Done, r.Outcome = k.now(), outcome
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
k.withdraw(&r)
|
||||
}
|
||||
data, _ := json.Marshal(r)
|
||||
if _, err := k.Store.Put(StateRequests, key, data); err != nil {
|
||||
@@ -367,3 +368,19 @@ func (k *Keeper) record(r *Request, what string) {
|
||||
k.logf("the hand act %q could not be recorded: %v", what, err)
|
||||
}
|
||||
}
|
||||
|
||||
// withdraw takes back the operator's ask of a drop or recreate the keeper refused (design 47 H2 §813 (6)): nothing is left
|
||||
// for the operator to answer once the request ended. A cancel that cannot be sent is said on the request's end.
|
||||
func (k *Keeper) withdraw(r *Request) {
|
||||
if r.Ask == "" || (r.Verb != VerbDrop && r.Verb != VerbRecreate) {
|
||||
return
|
||||
}
|
||||
if k.Cancel == nil {
|
||||
r.Error += "; its ask " + r.Ask + " is not withdrawn: the keeper holds no cancel"
|
||||
return
|
||||
}
|
||||
if err := k.Cancel(r.Ask); err != nil {
|
||||
k.logf("the ask %s of the refused request %s cannot be withdrawn: %v", r.Ask, r.ID, err)
|
||||
r.Error += fmt.Sprintf("; its ask %s could not be withdrawn: %v", r.Ask, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user