Skip to content

Commit

Permalink
Adds ability to parse parent/child wfRunId from a string in lhctl.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltmcnealy-lh committed Jan 22, 2024
1 parent 58d32fe commit 94890e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lhctl/cmd/wf_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ var getWfRunCmd = &cobra.Command{

common.PrintResp(getGlobalClient(cmd).GetWfRun(
requestContext(),
&model.WfRunId{
Id: args[0],
},
common.StrToWfRunId(args[0]),
))
},
}
Expand Down
21 changes: 21 additions & 0 deletions sdk-go/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"reflect"
"strconv"
"strings"

"github.com/littlehorse-enterprises/littlehorse/sdk-go/common/model"
"google.golang.org/protobuf/encoding/protojson"
Expand All @@ -28,6 +29,26 @@ func GetInputVarDefs(w *model.WfSpec) map[string]*model.VariableDef {
return out
}

func StrToWfRunId(id string) *model.WfRunId {
parts := strings.Split(id, "_")
return buildWfRunId(parts)
}

func buildWfRunId(parts []string) *model.WfRunId {
if len(parts) == 0 {
return nil
}

currentID := parts[len(parts)-1]
parentParts := parts[:len(parts)-1]
parent := buildWfRunId(parentParts)

return &model.WfRunId{
Id: currentID,
ParentWfRunId: parent,
}
}

func GetWfRunIdFromTaskSource(source *model.TaskRunSource) *model.WfRunId {
switch s := source.TaskRunSource.(type) {
case *model.TaskRunSource_UserTaskTrigger:
Expand Down

0 comments on commit 94890e5

Please sign in to comment.