Copy the kept call's ask id from its request header into the call's _meta as mesh/ask
Every tool call and seat verb the tool runner serves hands the bundle the ask id the kept call set in the header x-ask (stdio.AskHeader) under _meta mesh/ask (stdio.MetaAsk), beside mesh/call; a call whose header carries none names none. Builds: design 47 H2 §775, H-A-351
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/membership"
|
||||
"log"
|
||||
"regexp"
|
||||
@@ -626,7 +627,7 @@ type reply struct {
|
||||
|
||||
// answerOn answers one subject with one handler, and says which machine answered (ADR 0159).
|
||||
func (c *Conn) answerOn(subject, queue string, h Handler) (func(), error) {
|
||||
return c.answerCalledOn(subject, queue, func(_ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
return c.answerCalledOn(subject, queue, func(_, _ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
}
|
||||
|
||||
// answerCalledOn answers one subject, handing the handler the caller the subject a call arrived on names:
|
||||
@@ -636,7 +637,11 @@ func (c *Conn) answerCalledOn(subject, queue string, h CalledHandler) (func(), e
|
||||
cb := func(msg *nats.Msg) {
|
||||
go func() {
|
||||
var r reply
|
||||
result, err := h(callerOn(subject, msg.Subject), json.RawMessage(msg.Data))
|
||||
ask := ""
|
||||
if msg.Header != nil {
|
||||
ask = msg.Header.Get(stdio.AskHeader)
|
||||
}
|
||||
result, err := h(callerOn(subject, msg.Subject), ask, json.RawMessage(msg.Data))
|
||||
// A call the runner's drain cut at its stop is answered nothing: its caller sees a transport fault (design 47 H2
|
||||
// §813 (12)).
|
||||
var unanswered interface{ Unanswered() bool }
|
||||
@@ -695,7 +700,7 @@ func nullable(v any) any {
|
||||
|
||||
// HandleSubject answers a subject outright: a seat's verb where the mesh issued it.
|
||||
func (c *Conn) HandleSubject(subject string, h Handler) (func(), error) {
|
||||
return c.HandleSubjectCalled(subject, func(_ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
return c.HandleSubjectCalled(subject, func(_, _ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
}
|
||||
|
||||
// HandleSubjectCalled answers a tool subject and its caller-named counterpart (novox/hq issue 365): a call on
|
||||
@@ -733,7 +738,7 @@ func (c *Conn) answerBoth(subject, queue string, h CalledHandler) (func(), error
|
||||
// Handle serves `<module>.<tool>` where the mesh issued that module, and follows its membership:
|
||||
// when a new one arrives, it serves where it now says and stops where it no longer does.
|
||||
func (c *Conn) Handle(key string, h Handler) (func(), error) {
|
||||
return c.HandleCalled(key, func(_ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
return c.HandleCalled(key, func(_, _ string, body json.RawMessage) (any, error) { return h(body) })
|
||||
}
|
||||
|
||||
// HandleCalled is Handle telling the handler who called: the bus user a caller-named subject names, or "" for
|
||||
|
||||
@@ -106,8 +106,9 @@ func callerOn(pattern, subject string) string {
|
||||
return UserOfToken(subject[dot+1:])
|
||||
}
|
||||
|
||||
// CalledHandler answers one call, told who called: the bus user the subject named, or "" when it named none.
|
||||
type CalledHandler func(caller string, body json.RawMessage) (any, error)
|
||||
// CalledHandler answers one call, told who called: the bus user the subject named, or "" when it named none; and the ask id the
|
||||
// call carried in its request header stdio.AskHeader, or "" (design 47 H2 §775, H-A-351).
|
||||
type CalledHandler func(caller, ask string, body json.RawMessage) (any, error)
|
||||
|
||||
// callers is what a connection keeps of its caller-named calls: those in flight, by subject, so a refused
|
||||
// publish ends its call at once instead of after RequestTimeout.
|
||||
|
||||
@@ -58,7 +58,7 @@ type heard struct {
|
||||
callers []string
|
||||
}
|
||||
|
||||
func (h *heard) handler(caller string, _ json.RawMessage) (any, error) {
|
||||
func (h *heard) handler(caller, _ string, _ json.RawMessage) (any, error) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
h.callers = append(h.callers, caller)
|
||||
@@ -79,7 +79,7 @@ func TestACallerFallsBackAtOnceWhereNothingServesTheCallerNamedSubject(t *testin
|
||||
h := &heard{}
|
||||
// An older runtime: the subject that names no caller, alone.
|
||||
stop, err := server.HandleSubject("mesh.mod.ledger.tool.who", func(body json.RawMessage) (any, error) {
|
||||
return h.handler("", body)
|
||||
return h.handler("", "", body)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -223,7 +223,7 @@ func TestACallWaitsTheBoundItsVerbNamesAndTimesOutThere(t *testing.T) {
|
||||
url := grantedBus(t, map[string][]string{"anchor.node-tools": {"_INBOX.>"}, "shanks.node-tools": {"mesh.mod.*.tool.>"}})
|
||||
server := dial(t, url, "node-tools", "anchor", "anchor.node-tools")
|
||||
release := make(chan struct{})
|
||||
stop, err := server.HandleSubjectCalled("mesh.mod.ledger.tool.slow", func(string, json.RawMessage) (any, error) {
|
||||
stop, err := server.HandleSubjectCalled("mesh.mod.ledger.tool.slow", func(string, string, json.RawMessage) (any, error) {
|
||||
<-release
|
||||
return map[string]any{}, nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user