Skip to content

Commit

Permalink
fix(lhctl): Post events with empty payload (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduwercamacaro authored Aug 28, 2024
1 parent e181936 commit 84c44fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/interrupt-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ lhctl run example-interrupt-handler
lhctl get wfRun <wf run id>
# Note that it is 'RUNNING'. Next, post an external event using the following:
lhctl postEvent <wf run id> interruption-event NULL
lhctl postEvent <wf run id> interruption-event
# Then inspect the wfRun:
# Note that the threadRuns number 1 is 'ERROR' with type 'INTERRUPT'
Expand Down
25 changes: 12 additions & 13 deletions lhctl/internal/post_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,31 @@ currently do not carry Schema information (this will change in a future release)
The payload is deserialized according to the type. JSON objects should be provided as
a string; BYTES objects should be b64-encoded.
It's also possible to pass a null input:
lhctl postEvent <wfRunId> <externalEventName> NULL
It's also possible to pass an empty input:
lhctl postEvent <wfRunId> <externalEventName>
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 2 {
log.Fatal("Required args: <wfRunId> <externalEventName> <varType> <payload> or <wfRunId> <externalEventName> (to send a null payload)")
log.Fatal("Required args: <wfRunId> <externalEventName> <varType> <payload> or <wfRunId> <externalEventName> (to send an empty payload)")
}

wfRunIdStr, eedName, varTypeStr := args[0], args[1], args[2]
varType, validVarType := lhproto.VariableType_value[varTypeStr]
wfRunIdStr, eedName := args[0], args[1]

wfRunId := littlehorse.StrToWfRunId(wfRunIdStr)

if !validVarType {
log.Fatal(
"Unrecognized varType. Valid options: INT, STR, BYTES, BOOL, JSON_OBJ, JSON_ARR, DOUBLE or NULL.",
)
}

varTypeEnum := lhproto.VariableType(varType)

content := &lhproto.VariableValue{}

if len(args) == 4 {
varTypeStr := args[2]
payloadStr := args[3]

varType, validVarType := lhproto.VariableType_value[varTypeStr]
if !validVarType {
log.Fatal(
"Unrecognized varType. Valid options: INT, STR, BYTES, BOOL, JSON_OBJ, JSON_ARR or DOUBLE.",
)
}
varTypeEnum := lhproto.VariableType(varType)
var err error
content, err = littlehorse.StrToVarVal(payloadStr, varTypeEnum)
if err != nil {
Expand Down

0 comments on commit 84c44fb

Please sign in to comment.