Merge main into feat/47-G-join11: the tool runner's mesh/stream.publish (issue 1979)
mesh/delivery merged: source.main moved to novox/mesh-tools@a96df478d498
mesh/delivery-group group feat/47-G-join12 merged: every member is merged
mesh/check failed (2): mesh-delivery-checker: no published of the tagged version of go-meshconditions of me…; and 1 more | 6be5679a0d58 on a96df478d498
mesh/delivery merged: source.main moved to novox/mesh-tools@a96df478d498
mesh/delivery-group group feat/47-G-join12 merged: every member is merged
mesh/check failed (2): mesh-delivery-checker: no published of the tagged version of go-meshconditions of me…; and 1 more | 6be5679a0d58 on a96df478d498
The capability stream-publish is stated under mesh-sdk's word (buscalls.StreamPublishWord) and in the runtime artifact's states, so G's test that the stated words are the manifest's states holds; the publish uses G's exported JetStream. Builds: design 47 G §545, §622; design 42 zfs-owns-zfs A-42, A-44 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -276,6 +276,41 @@ func (c *Conn) StreamFill(module string, r buscalls.StreamRequest) (buscalls.Str
|
||||
return c.streamFill(b.Stream)
|
||||
}
|
||||
|
||||
// StreamPublish says one event on the module's own bound stream, by an acknowledged publish on the binding's subject plus
|
||||
// "." plus the event, the id as the message id (design 42 zfs-owns-zfs, A-42). The module's own binding alone: another
|
||||
// module's, and a binding that is not a stream, are refused by Binding.
|
||||
func (c *Conn) StreamPublish(module string, r buscalls.StreamPublishRequest) (buscalls.StreamPublished, error) {
|
||||
b, err := c.streamBinding(module, r.Stream)
|
||||
if err != nil {
|
||||
return buscalls.StreamPublished{}, err
|
||||
}
|
||||
if b.Subject == "" {
|
||||
return buscalls.StreamPublished{}, fmt.Errorf("%s's stream %q has no subject to say an event on", module, r.Stream)
|
||||
}
|
||||
if r.Event == "" || strings.ContainsAny(r.Event, " *>\t\r\n") || strings.HasPrefix(r.Event, ".") || strings.HasSuffix(r.Event, ".") {
|
||||
return buscalls.StreamPublished{}, fmt.Errorf("the event %q is not a name to say on %s's stream %q", r.Event, module, r.Stream)
|
||||
}
|
||||
body := []byte(r.Body)
|
||||
if len(body) == 0 {
|
||||
body = []byte("null")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), StateTimeout)
|
||||
defer cancel()
|
||||
js, err := c.JetStream()
|
||||
if err != nil {
|
||||
return buscalls.StreamPublished{}, err
|
||||
}
|
||||
var opts []jetstream.PublishOpt
|
||||
if r.ID != "" {
|
||||
opts = append(opts, jetstream.WithMsgID(r.ID))
|
||||
}
|
||||
ack, err := js.Publish(ctx, b.Subject+"."+r.Event, body, opts...)
|
||||
if err != nil {
|
||||
return buscalls.StreamPublished{}, fmt.Errorf("the event %s was not acknowledged on %s's stream %q: %w", r.Event, module, r.Stream, err)
|
||||
}
|
||||
return buscalls.StreamPublished{Sequence: ack.Sequence}, nil
|
||||
}
|
||||
|
||||
// StreamReadMost is the most messages one read answers.
|
||||
const StreamReadMost = 1000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user