Documentation
¶
Overview ¶
Package nodes_dispatch provides the `dispatch` action, which selects one action from a named pool (or explicit member list) and invokes it with the supplied payload. On failure it falls through the remaining members.
Typical use:
{ members: "log.info,runtime.noop", payload: { value: "x" } } -> dispatch.run
{ pool: "workers", chosen: "log.info", payload: .data } -> dispatch.run
Index ¶
Constants ¶
View Source
const ID = "nodes_dispatch"
Variables ¶
View Source
var Dispatch = action.New("dispatch.run", func(ctx context.Context, req DispatchReq) (any, error) { resolver := contracts.ActionResolverFromContext(ctx) if resolver == nil { return nil, xerr.Internal("dispatch: no action resolver in context") } members := req.Members if members == "" && req.Pool != "" { pools := contracts.PoolsFromContext(ctx) if pools == nil { return nil, xerr.Internal("dispatch: pool table not available in context") } listed, ok := pools[req.Pool] if !ok { return nil, xerr.NotFound("dispatch: pool not declared: " + req.Pool) } members = strings.Join(listed, ",") } names := splitMembers(members) if len(names) == 0 { return nil, xerr.BadRequest("dispatch: members is empty") } if req.Chosen != "" { if target, ok := resolver.Action(req.Chosen); ok { if output, err := action.InvokeAny(ctx, target, req.Payload); err == nil { return output, nil } } } if req.Fallback != "" { if target, ok := resolver.Action(req.Fallback); ok { if output, err := action.InvokeAny(ctx, target, req.Payload); err == nil { return output, nil } } } var lastErr error for _, name := range names { target, ok := resolver.Action(name) if !ok { lastErr = xerr.NotFound("dispatch: member not registered: " + name) continue } output, err := action.InvokeAny(ctx, target, req.Payload) if err == nil { return output, nil } lastErr = err } if lastErr == nil { lastErr = xerr.NotFound("dispatch: no member succeeded") } return nil, lastErr }).Description("Selects one action from a pool or list and invokes it"). Tag("dispatch", "pool", "routing"). Build()
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.