-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add workflow stack
command
#457
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a59a9af
Add `workflow stack` command
Sushisource e15d105
Stop autoformatting my markdown intellij
Sushisource bfca603
Review comments
Sushisource d0c9c09
Merge branch 'cli-rewrite' into workflow-stack
Sushisource 5cf8a6a
Fix wonky github merge whitespacing
Sushisource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,13 @@ import ( | |
|
||
"github.com/fatih/color" | ||
"github.com/google/uuid" | ||
"github.com/temporalio/cli/temporalcli/internal/printer" | ||
"go.temporal.io/api/batch/v1" | ||
"go.temporal.io/api/common/v1" | ||
"go.temporal.io/api/enums/v1" | ||
"go.temporal.io/api/query/v1" | ||
"go.temporal.io/api/workflowservice/v1" | ||
"go.temporal.io/sdk/client" | ||
|
||
"github.com/temporalio/cli/temporalcli/internal/printer" | ||
) | ||
|
||
func (c *TemporalWorkflowCancelCommand) run(cctx *CommandContext, args []string) error { | ||
|
@@ -55,60 +54,8 @@ func (*TemporalWorkflowDeleteCommand) run(*CommandContext, []string) error { | |
} | ||
|
||
func (c *TemporalWorkflowQueryCommand) run(cctx *CommandContext, args []string) error { | ||
cl, err := c.Parent.ClientOptions.dialClient(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer cl.Close() | ||
|
||
// Get input payloads | ||
input, err := c.buildRawInputPayloads() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryRejectCond := enums.QUERY_REJECT_CONDITION_UNSPECIFIED | ||
switch c.RejectCondition.Value { | ||
case "": | ||
case "not_open": | ||
queryRejectCond = enums.QUERY_REJECT_CONDITION_NOT_OPEN | ||
case "not_completed_cleanly": | ||
queryRejectCond = enums.QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY | ||
default: | ||
return fmt.Errorf("invalid query reject condition: %v, valid values are: 'not_open', 'not_completed_cleanly'", c.RejectCondition) | ||
} | ||
|
||
result, err := cl.WorkflowService().QueryWorkflow(cctx, &workflowservice.QueryWorkflowRequest{ | ||
Namespace: c.Parent.Namespace, | ||
Execution: &common.WorkflowExecution{WorkflowId: c.WorkflowId, RunId: c.RunId}, | ||
Query: &query.WorkflowQuery{ | ||
QueryType: c.Type, | ||
QueryArgs: input, | ||
}, | ||
QueryRejectCondition: queryRejectCond, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("querying workflow failed: %w", err) | ||
} | ||
|
||
if result.QueryRejected != nil { | ||
return fmt.Errorf("query was rejected, workflow has status: %v\n", result.QueryRejected.GetStatus()) | ||
} | ||
|
||
if cctx.JSONOutput { | ||
return cctx.Printer.PrintStructured(result, printer.StructuredOptions{}) | ||
} | ||
|
||
cctx.Printer.Println(color.MagentaString("Query result:")) | ||
output := struct { | ||
QueryResult json.RawMessage `cli:",cardOmitEmpty"` | ||
}{} | ||
output.QueryResult, err = cctx.MarshalFriendlyJSONPayloads(result.QueryResult) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal query result: %w", err) | ||
} | ||
return cctx.Printer.PrintStructured(output, printer.StructuredOptions{}) | ||
return queryHelper(cctx, c.Parent, c.PayloadInputOptions, | ||
c.Type, c.RejectCondition, c.WorkflowReferenceOptions) | ||
} | ||
|
||
func (*TemporalWorkflowResetBatchCommand) run(*CommandContext, []string) error { | ||
|
@@ -163,8 +110,9 @@ func (c *TemporalWorkflowSignalCommand) run(cctx *CommandContext, args []string) | |
return nil | ||
} | ||
|
||
func (*TemporalWorkflowStackCommand) run(*CommandContext, []string) error { | ||
return fmt.Errorf("TODO") | ||
func (c *TemporalWorkflowStackCommand) run(cctx *CommandContext, args []string) error { | ||
return queryHelper(cctx, c.Parent, PayloadInputOptions{}, | ||
"__stack_trace", c.RejectCondition, c.WorkflowReferenceOptions) | ||
} | ||
|
||
func (c *TemporalWorkflowTerminateCommand) run(cctx *CommandContext, _ []string) error { | ||
|
@@ -347,3 +295,67 @@ func startBatchJob(cctx *CommandContext, cl client.Client, req *workflowservice. | |
cctx.Printer.Printlnf("Started batch for job ID: %v", req.JobId) | ||
return nil | ||
} | ||
|
||
func queryHelper(cctx *CommandContext, | ||
parent *TemporalWorkflowCommand, | ||
inputOpts PayloadInputOptions, | ||
queryType string, | ||
rejectCondition StringEnum, | ||
execution WorkflowReferenceOptions, | ||
) error { | ||
cl, err := parent.ClientOptions.dialClient(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer cl.Close() | ||
|
||
// Get input payloads | ||
input, err := inputOpts.buildRawInputPayloads() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryRejectCond := enums.QUERY_REJECT_CONDITION_UNSPECIFIED | ||
switch rejectCondition.Value { | ||
case "": | ||
case "not_open": | ||
queryRejectCond = enums.QUERY_REJECT_CONDITION_NOT_OPEN | ||
case "not_completed_cleanly": | ||
queryRejectCond = enums.QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY | ||
default: | ||
return fmt.Errorf("invalid query reject condition: %v, valid values are: 'not_open', 'not_completed_cleanly'", rejectCondition) | ||
} | ||
|
||
result, err := cl.WorkflowService().QueryWorkflow(cctx, &workflowservice.QueryWorkflowRequest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentioned in other review, and don't have to change, but this could use the high-level |
||
Namespace: parent.Namespace, | ||
Execution: &common.WorkflowExecution{WorkflowId: execution.WorkflowId, RunId: execution.RunId}, | ||
Query: &query.WorkflowQuery{ | ||
QueryType: queryType, | ||
QueryArgs: input, | ||
}, | ||
QueryRejectCondition: queryRejectCond, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("querying workflow failed: %w", err) | ||
} | ||
|
||
if result.QueryRejected != nil { | ||
return fmt.Errorf("query was rejected, workflow has status: %v", result.QueryRejected.GetStatus()) | ||
} | ||
|
||
if cctx.JSONOutput { | ||
return cctx.Printer.PrintStructured(result, printer.StructuredOptions{}) | ||
} | ||
|
||
cctx.Printer.Println(color.MagentaString("Query result:")) | ||
output := struct { | ||
QueryResult json.RawMessage `cli:",cardOmitEmpty"` | ||
}{} | ||
output.QueryResult, err = cctx.MarshalFriendlyJSONPayloads(result.QueryResult) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal query result: %w", err) | ||
} | ||
|
||
return cctx.Printer.PrintStructured(output, printer.StructuredOptions{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory with how string-enum works this should never get this far, but I support the default anyways