node-tools: say whose words a refused event is (hq issue 276)
"plex did not take radarr.download.completed: Unexpected end of JSON input" read as the runtime failing to parse the bundle's answer. It was plex's own handler error, relayed. A bundle's error answer is now a launch.Refused, and the line says the handler answered an error, quotes it, names the event id and the delay before the next offer; the runtime's own failures (no answer in time, bundle exited) are said as before. The rule, unchanged and now tested: any mesh/event answer that is not an error takes the event, whatever its result says, including none.
This commit is contained in:
@@ -65,6 +65,17 @@ type Bus interface {
|
||||
// EventTimeout bounds how long a bundle has to handle one event before it is offered again.
|
||||
var EventTimeout = 2 * time.Minute
|
||||
|
||||
// Refused is a bundle's error answer to what the runtime asked it: the bundle's own words, as opposed
|
||||
// to the runtime not reaching it (not running, exited, no answer in time). For `mesh/event` it is the
|
||||
// one way a bundle says it did not take an event: any answer that is not an error — `{}`, `null`, no
|
||||
// result at all — takes it (mesh-sdk, "Taking an event"; novox/hq issue 276).
|
||||
type Refused struct {
|
||||
Method string
|
||||
Message string
|
||||
}
|
||||
|
||||
func (r *Refused) Error() string { return r.Message }
|
||||
|
||||
// Restart backoff: a bundle that exits is started again at once, then after growing pauses while it
|
||||
// keeps exiting, back to at once once it has run a while.
|
||||
var (
|
||||
@@ -144,6 +155,7 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
|
||||
if c == nil {
|
||||
return errors.New(module + "'s bundle is not running to take its events")
|
||||
}
|
||||
// Taken unless the answer is an error; what a result says is not read (see Refused).
|
||||
_, err := c.ask(module, "mesh/event", map[string]any{"envelope": envelope}, EventTimeout)
|
||||
return err
|
||||
}
|
||||
@@ -528,7 +540,7 @@ func (c *child) ask(module, method string, params any, timeout time.Duration) (j
|
||||
if msg == "" {
|
||||
msg = "the bundle refused the request"
|
||||
}
|
||||
return nil, errors.New(msg)
|
||||
return nil, &Refused{Method: method, Message: msg}
|
||||
}
|
||||
return m.Result, nil
|
||||
case <-c.dead:
|
||||
|
||||
Reference in New Issue
Block a user