propagate a ctx all the way from input to output of a route

This commit is contained in:
Joel Wetzell
2025-12-28 12:21:58 -06:00
parent 12de947f3d
commit f97f9b9fc9
18 changed files with 21 additions and 22 deletions

View File

@@ -3,7 +3,6 @@ package showbridge
import (
"context"
"errors"
"fmt"
"log/slog"
"sync"
@@ -129,13 +128,13 @@ func (r *Router) Stop() {
r.contextCancel()
}
func (r *Router) HandleInput(sourceId string, payload any) (bool, []route.RouteIOError) {
func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any) (bool, []route.RouteIOError) {
var routeIOErrors []route.RouteIOError
routeFound := false
for routeIndex, routeInstance := range r.RouteInstances {
if routeInstance.Input() == sourceId {
routeFound = true
routeContext := context.WithValue(r.Context, route.SourceContextKey, sourceId)
routeContext := context.WithValue(ctx, route.SourceContextKey, sourceId)
payload, err := routeInstance.ProcessPayload(routeContext, payload)
if err != nil {
@@ -177,8 +176,8 @@ func (r *Router) HandleOutput(ctx context.Context, destinationId string, payload
outputErrors = []error{}
}
outputErrors = append(outputErrors, err)
r.logger.Error("unable to route output", "module", moduleInstance.Id(), "error", err)
}
// r.logger.Error("unable to route output", "module", moduleInstance.Id(), "error", err)
}
}
return outputErrors