package main import ( "context" "encoding/json" "fmt" "time" "github.com/google/uuid" "tulpa.dev/within/wasmcloud/cmd/internal" "within.website/ln" "within.website/ln/opname" ) func runHandler(ctx context.Context, hdlr Handler, timeout time.Duration, message []byte) (*internal.ExecResponse, error) { ctx = opname.With(ctx, "invoke") execID := uuid.New().String() er := internal.ExecRequest{ WASMCID: hdlr.Path, Name: hdlr.Name, Data: message, Env: map[string]string{ "RUN_ID": execID, "MAGIC_CONCH": "yes", }, UUID: execID, } encData, err := json.Marshal(er) if err != nil { return nil, fmt.Errorf("can't encode job: %w", err) } f := ln.F{ "name": hdlr.Name, "run_id": execID, } ln.Log(ctx, ln.Info("starting run"), f) msg, err := nc.Request(internal.TopicName, encData, timeout) if err != nil { return nil, fmt.Errorf("can't submit job: %w", err) } var resp internal.ExecResponse err = json.Unmarshal(msg.Data, &resp) if err != nil { return nil, fmt.Errorf("can't unmarshal response: %w", err) } return &resp, nil }